Best method to set different layout for different pages in angular 4

后端 未结 4 684
孤街浪徒
孤街浪徒 2020-12-04 06:16

I am new to angular 4. What I\'m trying to achieve is to set different layout headers and footers for different pages in my app. I have three different cases:

4条回答
  •  渐次进展
    2020-12-04 07:00

    you can use child e.g.

    const appRoutes: Routes = [
        { path: '', component: MainComponent,
            children:{
                { path: 'home'  component:HomeComponent},
                { path: 'about', component: AboutComponent},
                { path: 'contact', component: ContactComponent},
                   ..others that share the same footer and header...
    
            }
        },
        { path: 'login', component: LoginComponent },
        { path: 'register', component: RegisterComponent },
        { path: 'admin', component:AdminComponent, 
             children{
                { path: 'dashboard', component: DashboardComponent },
                { path: 'profile', component: ProfileComponent }
                   ..others that share the same footer and header...
             }
        }
        { path: '**', redirectTo: '' }
    ];
    

    MainComponent and AdminComponent like

    
    
    
    

    the post talk about separate in diferent files the routes

提交回复
热议问题