我有一条主线
app.routing.module.ts
因此:
const routes: Routes = [
{ path: 'home', component: HomeComponent },
{ path: 'login', component: LoginComponent },
{ path: '', redirectTo: '/home', pathMatch: 'full' }
];
@NgModule({
imports: [
RouterModule.forRoot(routes),
],
exports: [ RouterModule ]
})
export class AppRoutingModule {}
然后是几个子路由模块:
const routes: Routes = [
{ path: 'AbcRoute1', component: AbcRoute1Component },
{ path: 'AbcRoute2', component: AbcRoute2Component }
];
@NgModule({
imports: [ RouterModule.forChild(routes) ],
exports: [ RouterModule ]
})
export class AbcRoutingModule {}
const routes: Routes = [
{ path: 'DefRoute1', component: DefRoute1Component },
{ path: 'DefRoute2', component: DefRoute2Component }
];
@NgModule({
imports: [ RouterModule.forChild(routes) ],
exports: [ RouterModule ]
})
export class DefRoutingModule {}
我指的是“包罗万象”路线:
{ path: '**', redirectTo: '/home', pathMatch: 'full' }
如果我把它放在
AppRoutingModule
,如果它不匹配
批准模块
。例如,我无法
https://myapp/DefRoute1
定义于
DefRoutingModule
如果我把它放进去
AbcRoutingModule
,那么所有的本地路线都能正常工作
解布线模块
不起作用。
我应该把它放在哪里,这样只有当我的所有路由模块都无法匹配url时,它才会匹配?