小编Ana*_*dan的帖子

Angular2路由器配置,前缀pathMatch不起作用

根据我从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)

angular2-routing angular

7
推荐指数
2
解决办法
2万
查看次数

标签 统计

angular ×1

angular2-routing ×1