如何在注销后默认显示登录页面



我想在注销后显示登录屏幕。

目前注销后没有LogoutModule,我的页面重定向到一个空白屏幕,如果我按照文档实现它,它会重定向到主页。

文件参考:https://sap.github.io/spartacus/modules/LogoutModule.html

@NgModule({

imports: [
PageLayoutModule,
RouterModule.forChild([
{
path: null,
canActivate: [LogoutGuard, CmsPageGuard],
component: PageLayoutComponent,
data: { cxRoute: 'logout' },
},
]),
],
})

我已经尝试过保护我的主页,但如果我这样做,我根本无法注销,也就是说,如果我点击注销,什么都不会发生。

您可以通过覆盖LogoutGuard中的默认getRedirectUrl来实现这一点。

目前,当且仅当它是一个关闭的商店时,基类在注销时重定向到登录页面。也就是说,用户必须在执行任何操作之前登录(提前登录(。

如何覆盖LogoutGuard行为的一个示例是执行以下操作:

1-创建您的自定义注销保护

@Injectable({
providedIn: 'root',
})
export class NewLogoutGuard extends LogoutGuard {
constructor(
auth: AuthService,
cms: CmsService,
semanticPathService: SemanticPathService,
protectedRoutes: ProtectedRoutesService,
router: Router,
authRedirectService: AuthRedirectService
) {
super(
auth,
cms,
semanticPathService,
protectedRoutes,
router,
authRedirectService
);
}
protected getRedirectUrl(): UrlTree {
return this.router.parseUrl(this.semanticPathService.get('login'));
}
}

2-通过提供新的注销保护来混淆类提供者

{ provide: LogoutGuard, useExisting: NewLogoutGuard },

最新更新