停用 ngx-rocket angular 7 初学者工具包中某些页面的登录屏幕
Deactivate Login Screen for certain pages in ngx-rocket angular 7 starter kit
我正在使用 ngx-rocket angular7 入门套件。它有一个防护装置,如果我还没有登录,它会让登录屏幕弹出。要实现一个注册页面,我不想弹出登录屏幕,注册页面应该是 public。有谁知道如何在那里停用登录屏幕?
这取决于您如何实现注册页面、显示代码、定义 link 和注册路径。通常,该模板在辅助函数中使用 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') } }
])
];
我正在使用 ngx-rocket angular7 入门套件。它有一个防护装置,如果我还没有登录,它会让登录屏幕弹出。要实现一个注册页面,我不想弹出登录屏幕,注册页面应该是 public。有谁知道如何在那里停用登录屏幕?
这取决于您如何实现注册页面、显示代码、定义 link 和注册路径。通常,该模板在辅助函数中使用 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') } }
])
];