是否可以定义重复路线,其中一条路线受到保护而另一条路线不受保护?从概念上讲,我想用受保护的子路由定义受保护的父路由,并用不受保护的子路由定义不受保护的父路由。
请参阅下面的路线定义:
const routes: Routes = [
{
path: '',
pathMatch: 'full',
redirectTo: '/registration'
},
{
path: '',
component: AuthenticatedLayoutComponent,
canActivate: [AuthGuard],
children:[
{ path: 'dashboard', component: DashboardComponent },
{ path: 'registration', component: RegistrationComponent }
]
},
{
path: '',
component: NonAuthenticatedLayoutComponent,
children:[
{ path: 'registration', component: RegistrationComponent }
]
}
];
如果用户未经身份验证,则预期的行为将跳过第一个空路径路由,并与第二个空路径路由“ / registration”匹配。