我一直在试验数十种配置,试图让它发挥作用,但无法解决这个问题。
给定的url如下:
- https://domain.com仪表板
- https://domain.com/profile简介
- https://domain.com/anything ...捕获所有的 child 。
- https://domain.com/otherthing
anything
和 otherthing
可以是任何东西。
我希望路由配置可以工作,但最终接管了定义的路由,其中 https://domain.com/profile会触发 catchall ('**'),这看起来很奇怪,因为根据我的理解,catchall 应该只触发或捕获上面没有定义的路由:
app.module
有这个:
export const routes = [
{
path: '',
loadChildren: 'app/dashboard/dashboard.module'
},
{
path: 'profile',
loadChildren: 'app/profile/profile.module'
},
{
path: '**',
loadChildren: 'app/anything/anything.module'
}
];
@NgModule({
imports: [
BrowserModule,
RouterModule.forRoot(routes)
],
declarations: [AppComponent]
bootstrap: [AppComponent]
})
export class AppModule {}
anything.module
有这个:
const routes = [
{
path: ':id', // hoping to pick up the wildcard as param this way
component: AnyComponent,
children: [
{
path: 'edit',
component: EditComponent
}
]
}
];
@NgModule({
imports: [
CommonModule,
RouterModule.forChild(routes)
],
declarations: [
AnyComponent,
EditComponent
]
})
export default class AnythingModule {}
有没有办法使上述用例与 Angular Router 3.4.1 一起工作?
最佳答案
这是一年前问的。但是我使用的是 Angular 5.1.2,发现自己遇到了同样的问题
这是在问题 # 18139 上解决的路由器错误,我在我的 package.json 上更新到 5.2.1 以获得修复
"@angular/core": "^5.2.1",
"@angular/forms": "^5.2.1",
"@angular/http": "^5.2.1",
等...
关于Angular 路由器 '**' 通配符作为子路由的包罗万象?使用最新的 2.4.0 和路由器 3.4.1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40276372/