Это зависит от того, как вы реализуете свою страницу регистрации, показываете свой код, где вы определяете ссылку и маршрут для регистрации. Обычно этот шаблон использует AuthenticationGuard
в качестве вспомогательной функции. Проверьте About
модуль:
const routes: Routes = [
Shell.childRoutes([
{ path: 'about', component: AboutComponent, data: { title: extract('About') } }
])
];
Если вы определите свой регистрационный модуль с маршрутами без Shell.childRoutes
помощника, он не будет вызывать AuthenticationGuard
и, следовательно, не будет перенаправлять на login
. Как это:
const routes: Routes = [
{ path: 'register', component: RegisterComponent, data: { title: extract('Register') } }
];
Если вы также хотите сохранить оригинальную функциональность Shell
, маршруты могут быть следующими:
const routes: Routes = [
{
path: '',
component: ShellComponent,
children: [
{ path: 'register', component: RegisterComponent, data: { title: extract('Register') } }
],
// canActivate: [AuthenticationGuard],
// Reuse ShellComponent instance when navigating between child views
data: { reuse: true }
}
];
В качестве альтернативы, помощник может быть определен в Shell
сам:
export class Shell {
// existing helper
static childRoutes(routes: Routes): Route {
return {
path: '',
component: ShellComponent,
children: routes,
canActivate: [AuthenticationGuard],
// Reuse ShellComponent instance when navigating between child views
data: { reuse: true }
};
}
// add new helper without guard
static unAuthenticatedChildRoutes(routes: Routes): Route {
return {
path: '',
component: ShellComponent,
children: routes,
// Reuse ShellComponent instance when navigating between child views
data: { reuse: true }
};
}
}
А потом, в вашем компоненте:
const routes: Routes = [
Shell.unAuthenticatedChildRoutes([
{ path: 'register', component: RegisterComponent, data: { title: extract('Register') } }
])
];