Angular 角度布线和铺设加载模块的问题
给定以下路由配置: 以下模块在Angular 角度布线和铺设加载模块的问题,angular,Angular,给定以下路由配置: 以下模块在AppModule const routes: Routes = [ ... { path: "lazy", loadChildren: "app/modules/lazymodule#LazyModule" }, { path: "**", component: DemoComponent, pathMatch: "full" } ] @NgModule({ imports: [RouterModul
AppModule
const routes: Routes = [
...
{
path: "lazy",
loadChildren: "app/modules/lazymodule#LazyModule"
},
{
path: "**",
component: DemoComponent,
pathMatch: "full"
}
]
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
const routes: Routes = [
{
path: "",
component: LazyComponent,
pathMatch: "full"
},
{
path: ":test",
component: TestComponent
},
{
path: "try",
component: TryComponent,
pathMatch: "full",
}
];
@NgModule({
imports: [RouterModule.forChild(routes)]
})
以下模块在LazyModule
const routes: Routes = [
...
{
path: "lazy",
loadChildren: "app/modules/lazymodule#LazyModule"
},
{
path: "**",
component: DemoComponent,
pathMatch: "full"
}
]
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
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"])
最后一个有什么问题吗?
/lazy/try
匹配为:
{
path: ":test",
component: TestComponent
}
因此,应该使用try
作为:test
参数的值导航到TestComponent
如果要更改该路径,请更改路由顺序,使路径为“try”的路由位于路径为“test”的路由之前