首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >取消ngx火箭角7起动器组件中某些页面的登录屏幕

取消ngx火箭角7起动器组件中某些页面的登录屏幕
EN

Stack Overflow用户
提问于 2018-11-04 23:30:11
回答 1查看 597关注 0票数 0

我用的是ngx火箭angular7起动器。它实现了一个保护程序,如果我还没有登录,它将使登录屏幕弹出。为了实现注册页面,我不希望登录屏幕弹出,注册页面应该是公开的。有人知道如何在那里停用登录屏幕吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-11-04 23:52:06

这取决于您如何实现注册页面,显示代码,在哪里定义注册的链接和路由。通常,该模板在助手函数中使用AuthenticationGuard。检查About模块:

代码语言:javascript
复制
const routes: Routes = [
  Shell.childRoutes([
    { path: 'about', component: AboutComponent, data: { title: extract('About') } }
  ])
];

如果使用没有Shell.childRoutes助手的路由定义注册模块,它将不会触发AuthenticationGuard,因此不会重定向到login。如下所示:

代码语言:javascript
复制
const routes: Routes = [
    { path: 'register', component: RegisterComponent, data: { title: extract('Register') } }
];

如果还希望保留原始的Shell功能,则路由可以如下所示:

代码语言:javascript
复制
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中定义助手:

代码语言:javascript
复制
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 }
    };
  }
}

然后,在你的组成部分中:

代码语言:javascript
复制
const routes: Routes = [
  Shell.unAuthenticatedChildRoutes([
    { path: 'register', component: RegisterComponent, data: { title: extract('Register') } }
  ])
];
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53146527

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档