multiple layout for different pages in angular 2

后端 未结 4 1872
鱼传尺愫
鱼传尺愫 2020-11-29 17:59

I am building a angular2 app.

I have a login page- just 2 input (no header no footer no side bar)

when user login he should be navigated to a page with heade

4条回答
  •  广开言路
    2020-11-29 18:22

    You can solve your problem using child routes.

    See working demo at https://angular-multi-layout-example.stackblitz.io/ or edit at 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);
    

提交回复
热议问题