0

我有两个单独的页面用于登录和注册。我没有为这两个页面应用 AuthGuard。即使那样,当我导航到注册时,它也总是重定向到登录页面。

我试图检查 AuthGuard 类中的当前 url,以防止在 url 与注册页面匹配时重定向。但这对我不起作用。

这些是我的路线

const routes: Routes = [
  //unauthorised routes
  {
    path: 'login',
    component: LoginLayoutComponent,
    children : [
      {
        path: '',
        component: LoginComponent
      }
    ]
  },
  {
    path: 'signup',
    component: LoginLayoutComponent,
    children : [
      {
        path: '',
        component: SignupComponent
      }
    ]
  },
  {
    path: 'onboard',
    canActivate: [AuthGuard],
    component: LoginLayoutComponent,
    children: [
      {
        path: '',
        component: StepperComponent
      }
    ] 
  },
  //authorised routes
  {
    path: '',
    component: HomeLayoutComponent,
    canActivate: [AuthGuard],
    children : [
      {
        path: '',
        redirectTo: 'dashboard',
        pathMatch: 'full'
      },
      {
        path: 'dashboard',
        component: DashboardComponent
      }
    ] 
  }
];

预期的行为是 AuthGuard 不应在未应用的地方被触发。

4

1 回答 1

0

除了我上面的评论,这样的事情可能会有所帮助

{ path: '', component: HomeComponent },
{ 
    path: 'dashboard',
    component: DashboardComponent,
    canActivate: [AuthGuard] 
},
于 2019-08-12T13:52:25.543 回答