Angular(2+)中嵌套路线中的多个布局 [英] Multiple layouts in nested routes in Angular (2+)
问题描述
我正在创建一个类似Dashboard的应用程序.我想在Angular(2+)中实现以下布局计划:
I'm creating a Dashboard like application. I'd like to achieve the following layout plan in Angular (2+):
- 路线-名称-布局
- /-主页-具有表格和图表等的全宽布局
- /reports-报告页面-具有更多表格等的相同全角布局
- /login-登录页面-没有全角布局,只是屏幕中心的简单登录表单
- /signup-注册页面-没有全角布局,只是屏幕中心的简单注册表格
- /消息-电子邮件-全角布局
- /messages/new-新电子邮件-中等布局,不继承全角布局
等...
所以基本上我想做的是在某些(子)路由上完全替换<body>
的内容.
So basically what I'd like to do is to completely replace the contents of <body>
at some (child) routes.
这对我不利:针对不同对象的多种布局角2中的页面,因为我不想将/(根)重定向到/home之类的地方.
This is not good for me: multiple layout for different pages in angular 2 because I don't want to redirect / (root) to anywhere like /home.
此方法也不适合:如何在Angular2中切换布局
任何帮助都会很棒!
推荐答案
您可以使用子路由解决问题.
You can solve your problem using child routes.
在 https://angular-multi-layout-example.stackblitz.io上查看工作演示./或在 https://stackblitz.com/edit/angular-multi -layout-example
像下面一样设置您的路线
Set your route like below
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
这篇关于Angular(2+)中嵌套路线中的多个布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!