我有两个单独的页面用于登录和注册。我没有为这两个页面应用 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 不应在未应用的地方被触发。