添加查询参数时,Angular 5路由器不匹配

时间:2018-09-17 06:45:29

标签: angular angular-ui-router

I have Angular 5 routes config like this: 
const loginRoutes: Routes = [
  {
    path: '',
    component: RegistationComponent,
    children: [
      { path: '', redirectTo: 'sign-in', pathMatch: 'full' },
      { path: 'sign-in', component: SigninComponent },
      { path: 'sign-up', pathMatch: 'prefix', component: SignupComponent },
      { path: 'twofactor', component: TwofactorComponent },
    ]
  }
];

如果我浏览确切的路线,效果很好,但是当我添加查询参数时,说:

http://localhost:4200/login/reg/sign-up?inviteCode=b8f496ca68a37c174459

它将重定向回到sign-in路由。我该如何解决?

3 个答案:

答案 0 :(得分:1)

我发现了问题,并不是因为路由器配置,而是由于auth Guard服务执行了重定向。

答案 1 :(得分:0)

尝试将您的重定向路由更改为以下内容:

const loginRoutes: Routes = [
  {
    path: '',
    component: RegistationComponent,
    children: [
      { path: 'sign-in', component: SigninComponent },
      { path: 'sign-up', pathMatch: 'prefix', component: SignupComponent },
      { path: 'twofactor', component: TwofactorComponent },
      { path: '', redirectTo: 'sign-in', pathMatch: 'full' },
      { path: '**', redirectTo: 'sign-in', pathMatch: 'full' }
    ]
  }
];

更新:添加了path:''路线

答案 2 :(得分:0)

像这样定义它

  { path: 'sign-in/:invitecode', component: SigninComponent },