How to switch layouts in Angular2

后端 未结 4 560
野性不改
野性不改 2020-11-27 13:22

What is the best practices way of using two entirely different layouts in the same Angular2 application? For example in my /login route I want to have a very simple box hori

4条回答
  •  爱一瞬间的悲伤
    2020-11-27 13:50

    In Angular 4 (and probably also in Angular 2) you can do:

    const routes: Route[] = [
      {path: 'admin', redirectTo: 'admin/dashboard', pathMatch: 'full'},
      {
        path: 'admin',
        children: [
          {
            path: '', component: DefaultLayoutComponent,
            children: [
              {path: 'dashboard', component: DashboardComponent}
            ]
          },
          {
            path: '',
            children: [
              {path: 'login', component: LoginComponent}
            ]
          }
        ]
      }
    ]
    

    By using path: '' you won't have to invent different url namespaces in order to use a simple layout. This is what the views look like:

    index.html:

    
    

    default-layout.html:

    
    

提交回复
热议问题