我用的是ngx火箭angular7起动器。它实现了一个保护程序,如果我还没有登录,它将使登录屏幕弹出。为了实现注册页面,我不希望登录屏幕弹出,注册页面应该是公开的。有人知道如何在那里停用登录屏幕吗?
发布于 2018-11-04 23:52:06
这取决于您如何实现注册页面,显示代码,在哪里定义注册的链接和路由。通常,该模板在助手函数中使用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 it self中定义助手:
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') } }
])
];https://stackoverflow.com/questions/53146527
复制相似问题