从父级到子级路由的 navigateByUrl 不起作用
我会导航到我的应用程序中的一个子组件.
I would navigate to a sub component in my app.
this.router.navigateByUrl(this.rightsService.pathToRedirectTo).then((data) => {
console.log(data)
});
当我通过 /mainRoute
时它正在工作路由:
It's working when I pass /mainRoute
Routing :
{ path: 'mainRoute', loadChildren: () =>import('./xxx/xxxx').then(m => m.xxxModule) },
但当我通过 /mainRoute/subRoute/1
我的路由如下:
{ path: 'subRoute/:id', canActivate: [ViewGuard], 组件: ViewComponent },
我不知道为什么第二种情况不起作用?
I don't know why the second case is not working ?
这是我的父路由
{ path: 'login', component: LoginComponent },
{ path: 'mainRoute', loadChildren: () => import('./main/main.module').then(m => m.mainModule) },
{ path: '**', redirectTo: 'login' }];
然后在 mainModule 里面
Then inside mainModule
我有路由:
{ path: 'subRoute/:id', canActivate: [ViewGuard], component: ViewComponent },
{ path: 'subroute/:id/childRoute/:sId', canActivate: [SViewGuard], component: SiewComponent }];
请检查当您尝试重定向到 /mainRoute/subRoute/1
时返回的 ViewGuard
,似乎路由守卫可以返回 false
并且这可能是这个问题的原因,如果您为此路由或某些父组件使用任何拦截器,也请检查拦截器返回的值.
Check please what the return your ViewGuard
when you try to redirect to /mainRoute/subRoute/1
, seems that route guard can return false
and it could be a reason of this problem, also in case that you use any interceptors for this route or for some parent components, check what the value that interceptors return too.