Angular中嵌套路由中的多个布局(2)

前端之家收集整理的这篇文章主要介绍了Angular中嵌套路由中的多个布局(2)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在创建一个类似应用程序的仪表板.我想在Angular(2)中实现以下布局计划: @H_404_1@>路线 – 名称 – 布局
> / – 主页 – 带表格和图表的全宽布局等
> / reports – 报告页面 – 具有更多表格的相同全宽布局等
> / login – 登录页面 – 没有全宽布局,只是屏幕中心的简单登录表单
> /注册注册页面 – 没有全宽度布局,只是屏幕中心的简单注册表单
> / messages – 电子邮件 – 全宽布局
> / messages / new – 新电子邮件 – 中等布局,不是从全宽布局继承

@H_404_1@等等…

@H_404_1@所以基本上我想做的是完全替换< body>的内容.在某些(儿童)路线.

@H_404_1@这对我不好:multiple layout for different pages in angular 2因为我不想将/(root)重定向到像/ home这样的地方.

@H_404_1@这个也不适合:How to switch layouts in Angular2

@H_404_1@任何帮助都会很棒!

您可以使用子路径解决您的问题. @H_404_1@请参阅https://angular-multi-layout-example.stackblitz.io/的工作演示或https://stackblitz.com/edit/angular-multi-layout-example的编辑

@H_404_1@设置如下路线

  1. const appRoutes: Routes = [
  2.  
  3. //Site routes goes here
  4. {
  5. path: '',component: SiteLayoutComponent,children: [
  6. { path: '',component: HomeComponent,pathMatch: 'full'},{ path: 'about',component: AboutComponent }
  7. ]
  8. },// App routes goes here here
  9. {
  10. path: '',component: AppLayoutComponent,children: [
  11. { path: 'dashboard',component: DashboardComponent },{ path: 'profile',component: ProfileComponent }
  12. ]
  13. },//no layout routes
  14. { path: 'login',component: LoginComponent},{ path: 'register',component: RegisterComponent },// otherwise redirect to home
  15. { path: '**',redirectTo: '' }
  16. ];
  17.  
  18. export const routing = RouterModule.forRoot(appRoutes);
@H_404_1@推荐参考:http://www.tech-coder.com/2017/01/multiple-master-pages-in-angular2-and.html

猜你在找的Angularjs相关文章