从父级到子级路由的 navigateByUrl 不起作用 [英] navigateByUrl from parent to child route not working

查看:27
本文介绍了从父级到子级路由的 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.

这篇关于从父级到子级路由的 navigateByUrl 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆