Manage different base layouts in Angular2

偶尔善良 提交于 2019-12-12 17:26:14

问题


In my angularjs application with ui.router I can do following:

$stateProvider
        .state('app', {
            url: '',
            abstract: true,
            template: '<div data-ui-view></div>'
        })
        .state('app.auth', {
            url: '',
            abstract: true,
            controller: 'AuthShellController as vm',
            templateUrl: 'views/auth/auth-shell-view.html'
        })
        .state('app.ui', {
            abstract: true,
            templateUrl: 'views/ui-shell-view.html',
            controller: 'ShellController as vm'

and my angular2 application routes config:

const appRoutes:Routes = <Routes>[
{
    path: '',
    component: DashboardComponent,
},
{
    path: 'login',
    component: LoginComponent,
},
{
    path: 'presentation',
    children: [{
        path: 'new',
        component: PresentationComponent
    }, {
        path: ':id',
        component: PresentationComponent
    }]
},

];

In angularjs I can resolve same url by states, so if I have authorization state I render just login form without header, sidebar.

If I have application state I render shell with header, footer, sidebar and so on.

Question

How can I manage base layouts in angular2 router?


回答1:


I found a way that works for me to manage base layouts: https://stackblitz.com/github/jbojcic1/angular-routing-example?file=src%2Fapp%2Flayout%2Flayout-routing.module.ts In this example I have featureA and featureB modules which use base layout with header and sidebar and login feature which doesn't use any base layout.

The only thing I don't like here is that each time you add a new module which uses some base layout, you need to modify routing file for that base layout, because this violates open/closed principle.



来源:https://stackoverflow.com/questions/43469401/manage-different-base-layouts-in-angular2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!