根据我从Angular2路由器文档中的理解,路由配置默认pathMatch策略是"前缀","前缀"pathMatch策略意味着应用路由器只需要查看URL的开头并将其与正确的路由匹配.
参考:https://angular.io/docs/js/latest/api/router/index/Routes-type-alias.html#!#matching-strategy
话虽如此,通过以下配置我会假设ExampleComponent如果我导航到这条路线应该加载/abcdefg.
一个问题是这不起作用,我不确定有什么问题,我无法在谷歌或@angular/router源代码中找到关于此的更多信息.
谢谢您的帮助.
const ROUTES: Routes = [
{ path: '', component: MainLayoutComponent, pathMatch: 'prefix', canActivate: [AuthGuard], children: [
{ path:'abc', pathMatch: 'prefix', component: ExampleComponent},
{ path: '', component: HomepageComponent }
]},
];
export const ROUTING = RouterModule.forRoot(ROUTES, { useHash: false });
Run Code Online (Sandbox Code Playgroud)
更新#1,尝试GünterZöchbauer的建议.
新的路由器配置是:
现在/abc/defg有效,但没有/abcdefg
{ path:'abc', pathMatch: 'prefix',
children: [
{ path:'**', component:ExampleComponent},
]
}
Run Code Online (Sandbox Code Playgroud)