我正在创建一个类似应用程序的仪表板.我想在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@任何帮助都会很棒!
> / – 主页 – 带表格和图表的全宽布局等
> / 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@设置如下路线
@H_404_1@推荐参考:http://www.tech-coder.com/2017/01/multiple-master-pages-in-angular2-and.html
- 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);