给出以下路由配置:
以下模块已导入AppModule
内
const routes: Routes = [
...
{
path: "lazy",
loadChildren: "app/modules/lazymodule#LazyModule"
},
{
path: "**",
component: DemoComponent,
pathMatch: "full"
}
]
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
以下模块已导入LazyModule
内
const routes: Routes = [
{
path: "",
component: LazyComponent,
pathMatch: "full"
},
{
path: ":test",
component: TestComponent
},
{
path: "try",
component: TryComponent,
pathMatch: "full",
}
];
@NgModule({
imports: [RouterModule.forChild(routes)]
})
一旦LazyModule
已加载,我可以通过以下方式导航到TestComponent
:
this.router.navigate(["/lazy", "hello"])
但不通过
进入TryComponent
this.router.navigate(["/lazy/try"])
最后一个怎么了?
答案 0 :(得分:1)
/lazy/try
与以下项匹配:
{
path: ":test",
component: TestComponent
}
因此,应使用TestComponent
作为try
参数的值导航到:test
。
如果要更改此设置,请更改路由顺序,以使具有path: "try"
的路由位于具有path: ":test"
的路由之前。