angular - angular2登录页面的不同布局

标签 angular angular2-routing angular2-template

我的所有页面都有一个带有工具和侧边栏的正常布局,但当用户转到登录或注册页面时,它们不应该是可见的。在 AngularJS 中,使用 ui-router 很容易在您可以定义布局的所有其他页面之前包含一个路由。

但是如何在 Angular2 中使用本地路由器来实现呢?我应该使用 ngIf 来显示工具栏和侧边栏还是有更好的方法?

最佳答案

可以通过路由的 children 属性实现:

export const routes:RouterConfig = [
  //includes the login and registration route
  ...userRoutes,
  {
    path: '',
    //checks if the user is logged in
    canActivate: [Auth],
    //only contains a <route-outlet />
    component: LayoutComponent,
    //routes like /dashboard will only accessible when Auth returns true
    children: [
      //all children are 'protected'
      ...modulRoutes,
      ...dashboardRoutes,
    ]
  },
  //404 handling
  ...errorRoutes
];

我用的是angular2的3.0路由器

关于angular - angular2登录页面的不同布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38345848/

相关文章:

angular - 从服务返回的 Observable 的单元测试值(使用异步管道)

javascript - angular-cli 编译错误 + monorepo : error TS2451: Cannot redeclare block-scoped variable 'ngDevMode'

angular - HostListener onBlur 和 onFocus 没有在 angular4 中被触发

angular - 取消路由解析

angular - 如何在内存中使用两个不同 json 的 Web api

javascript - 需要帮助数据与 Observables 的 Angular 绑定(bind)

angular - 没有参数值的路由; Angular 路由重定向 - 我可以使用 redirectTo 来参数路径吗?

javascript - 如何防止对象/数组突变?

Angular 2.0.1 AsyncPipe 不适用于 Rx Subject

angular - 如何检查无法读取未定义的属性 'testUndefined'