加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-17 07:59:45 所属栏目:安全 来源:网络整理
导读:我正在创建一个类似应用程序的仪表板.我想在Angular(2)中实现以下布局计划: 路线 – 名称 – 布局 / – 主页 – 带表格和图表的全宽布局等 / reports – 报告页面 – 具有更多表格的相同全宽布局等 / login – 登录页面 – 没有全宽布局,只是屏幕中心的简单
我正在创建一个类似应用程序的仪表板.我想在Angular(2)中实现以下布局计划:

>路线 – 名称 – 布局
> / – 主页 – 带表格和图表的全宽布局等
> / reports – 报告页面 – 具有更多表格的相同全宽布局等
> / login – 登录页面 – 没有全宽布局,只是屏幕中心的简单登录表单
> /注册 – 注册页面 – 没有全宽度布局,只是屏幕中心的简单注册表单
> / messages – 电子邮件 – 全宽布局
> / messages / new – 新电子邮件 – 中等布局,不是从全宽布局继承

等等…

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

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

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

任何帮助都会很棒!

您可以使用子路径解决您的问题.

请参阅https://angular-multi-layout-example.stackblitz.io/的工作演示或https://stackblitz.com/edit/angular-multi-layout-example的编辑

设置如下路线

const appRoutes: Routes = [

    //Site routes goes here 
    { 
        path: '',component: SiteLayoutComponent,children: [
          { path: '',component: HomeComponent,pathMatch: 'full'},{ path: 'about',component: AboutComponent }
        ]
    },// App routes goes here here
    { 
        path: '',component: AppLayoutComponent,children: [
          { path: 'dashboard',component: DashboardComponent },{ path: 'profile',component: ProfileComponent }
        ]
    },//no layout routes
    { path: 'login',component: LoginComponent},{ path: 'register',component: RegisterComponent },// otherwise redirect to home
    { path: '**',redirectTo: '' }
];

export const routing = RouterModule.forRoot(appRoutes);

推荐参考:http://www.tech-coder.com/2017/01/multiple-master-pages-in-angular2-and.html

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读