【发布时间】:2020-06-15 12:50:54
【问题描述】:
当用户使用通配符输入错误的URL但由条件控制时,有没有办法处理重定向路由?
我的项目分别有3个主要模块,每个模块都有一些只能由用户角色访问的条件。
问题是我不知道如何按条件处理,我试过 canActivate 但它不起作用
main.ts:14 错误:路由“**”的配置无效。必须提供以下之一:component、redirectTo、children 或 loadChildren
这是我的一些代码。
const routes: Routes = [
{
path: '',
pathMatch: 'full',
redirectTo: 'customer1'
},
{
path: 'customer1',
component: RootOneComponent,
children: [
{
path: '',
pathMatch: 'full',
redirectTo: 'home'
},
{
path: 'home',
component: HomeOneComponent
},
{
path: '**',
component: PageNotFoundComponent
}
],
},
{
path: 'customer2',
component: RootTwoComponent,
children: [
{
path: '',
pathMatch: 'full',
redirectTo: 'home'
},
{
path: 'home',
component: HomeTwoComponent
},
{
path: 'BlogPicture',
loadChildren: () => import('./blog/blog.module').then(m => m.BlogModule)
},
{
path: '**',
component: PageNotFoundComponent
}
],
},
{
path: 'customer3',
component: RootThreeComponent,
children: [
{
path: '',
pathMatch: 'full',
redirectTo: 'home'
},
{
path: 'home',
component: HomeThreeComponent
},
{
path: 'blog-price',
loadChildren: () => import('./blog/blog.module').then(m => m.BlogModule)
},
{
path: '**',
component: PageNotFoundComponent
}
],
},
// wild card condition is there the way to manage this?
{
path: '**',
redirectTo: 'classic'
}
];
【问题讨论】:
标签: angular typescript angular8 angular-routing