Angular2 - Shared Layout for multiple modules

后端 未结 1 1192
野性不改
野性不改 2021-01-15 11:33

I build an Angular application with different modules. Each module handles distinct tasks. On my landing page, the user should login or register. It\'s a very lean layout wi

相关标签:
1条回答
  • 2021-01-15 11:56

    You can use parent/children routing to achieve this. Something like this should work (may need some tweaking depends on the other parts of your project)

    const routes: Routes = [
        {
            path: 'auth',
            component: Layout1
            canActivate: [NotLoggedInGuard],
            children: [
               { path: '', component: PublicAuthComponent }
            ]
        },
        {
            path: '',
            component: Layout2,
            canActivate: [LoggedInGuard],
            children: [
              { path: '', loadChildren: './path/to/module/feature.module#FeatureModule' }
            ]
        }
    ];
    

    Remember to put <router-outlet> inside both of Layout components.

    0 讨论(0)
提交回复
热议问题