angular路由如何一次进行多次重定向
2018-11-10 本文已影响0人
OnePiece索隆
以下面代码举例,当我们自动转入crisis-center时会发现并没有自动路由到/crisis-center/list,而是路由到/crisis-center,这是因为redirectTo的写法中带了'/',ng路由器无法判断从应用的根路由开始查找还是从当前激活路由开始查找
const appRoutes: Routes = [
{
path: 'admin',
},
{
path: 'crisis-center',
children: [
{ path: '', redirectTo: '/list', pathMatch: 'full' }
{ path: 'list', component: Listcomponent }
]
},
{ path: '', redirectTo: '/crisis-center', pathMatch: 'full' }
];
修改方式:
const appRoutes: Routes = [
{
path: 'admin',
},
{
path: 'crisis-center',
children: [
{ path: '', redirectTo: 'list', pathMatch: 'full' }
{ path: 'list', component: Listcomponent }
]
},
{ path: '', redirectTo: 'crisis-center', pathMatch: 'full' }
];