Angular 角度路由器-重定向到带有查询参数的URL时,无法匹配任何路由

Angular 角度路由器-重定向到带有查询参数的URL时,无法匹配任何路由,angular,angular-ui-router,angular-routing,angular-router,angular4-router,Angular,Angular Ui Router,Angular Routing,Angular Router,Angular4 Router,我在angular 4应用程序中使用angular router时遇到一些问题,同时使用returnUrl和查询字符串 因此,我指定了如下路线: const routes: Routes = [ { path: '', component: HomeComponent, canActivate: [AccessibilityGuard], canActivateChild: [AccessibilityGuard], children: [ { path:

我在angular 4应用程序中使用angular router时遇到一些问题,同时使用
returnUrl
和查询字符串

因此,我指定了如下路线:

const routes: Routes = [
{
  path: '',
  component: HomeComponent,
  canActivate: [AccessibilityGuard],
  canActivateChild: [AccessibilityGuard],
  children: [
    {
      path: 'info',
      component: InfoComponent,
      children: [
        {
          path: 'xpto/graphic',
          component: XptoGraphicComponent,
        },
      ]
    },
    ...
  ];
}];
在我的
可访问性Guard
中,我有以下内容:

...
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
  const token = CookieHelper.getCookie('accessToken');
  if(token == null || token == '') {
    this.router.navigate(['login']);
    return false;
  }
  ...
}
因此,考虑到我试图导航到我的
xptographicscomponent
的特定页面,我的URL可能类似于:
http://localhost:4200/info/xpto/graphic?a=1&b=2&c=3
。 如果我的
AccessibilityGuard
没有找到accessToken,它会将我重定向到登录页面。之后,我的url将是:
http://localhost:4200/login?returnUrl=/info/xpto/graphic?a=1&b=2&c=3

登录后,重定向不起作用,我的浏览器控制台出现以下错误:

Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'info/xpto/graphic?a=1&b=2&c=3'
只有当我的url中有查询参数以及
returnURL
时,才会出现此问题。
有没有办法解决这个问题?提前谢谢

可能是您的
/info…
url嵌套为
主路径的子路径吗?哦,很抱歉,实际上HomeComponent的路径是空字符串“”,而不是“home”。我已经更正了,对不起,你用什么代码来执行重定向?我以前使用过Router.navigateByUrl()。。。我正在使用
navigate()
,但即使使用
navigateByUrl
它似乎也不起作用……毕竟@96ethanh,你是对的,
navigateByUrl()
解决了它!我指的是
AccessibilityGuard
中的
navigate()
,而不是负责
returnUrl
的那个。谢谢:)