前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >如何将SAP Spartacus的默认home页面替换成login页面 - ProtectedRoutesService

如何将SAP Spartacus的默认home页面替换成login页面 - ProtectedRoutesService

作者头像
Jerry Wang
发布2021-04-06 15:29:55
6180
发布2021-04-06 15:29:55
举报

现状

We tried from CMS - we changed the starting-page of site to login page, made homepage as not-default and this brought the login page. However, it’s not refreshing or redirecting to HomePage after successful login.

解决方案

Is your homepage accessible only for authenticated users? If yes you can make use of protected routes (see ProtectedRoutesService) - setting homepage as default will redirect to login anyways and after authenticating user will be redirected back to the homepage.

ProtectedRoutes的意思是,此类Route是否应该activate,取决于AuthGuard.

如果是非ProtectedRoutes,则返回true.

代码语言:javascript
复制
@Injectable({ providedIn: 'root' })
export class ProtectedRoutesGuard implements CanActivate {
  constructor(
    protected service: ProtectedRoutesService,
    protected authGuard: AuthGuard
  ) {}

  /**
   * When the anticipated url is protected, it switches to the AuthGuard. Otherwise emits true.
   */
  canActivate(route: ActivatedRouteSnapshot): Observable<boolean | UrlTree> {
    let urlSegments: string[] = route.url.map((seg) => seg.path);

    // For the root path `/` ActivatedRoute contains an empty array of segments:
    urlSegments = urlSegments.length ? urlSegments : [''];

    if (this.service.isUrlProtected(urlSegments)) {
      return this.authGuard.canActivate();
    }
    return of(true);
  }
}
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2021-02-22 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 现状
  • 解决方案
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档