javascript - 在 Angular2 中管理不同的基本布局

标签 javascript angularjs angular typescript angular-ui-router

在带有 ui.router 的 angularjs 应用程序中,我可以执行以下操作:

$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'

和我的 angular2 应用程序路由配置:

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

];

在 angularjs 中,我可以按状态解析相同的 url,所以如果我有授权​​状态,我只呈现没有标题和侧边栏的登录表单。

如果我有应用程序状态,我会渲染带有页眉、页脚、边栏等的 shell。

问题

如何在 angular2 路由器中管理基本布局?

最佳答案

我找到了一种适合我管理基本布局的方法:https://stackblitz.com/github/jbojcic1/angular-routing-example?file=src%2Fapp%2Flayout%2Flayout-routing.module.ts 在这个例子中,我有 featureA 和 featureB 模块,它们使用带有标题和侧边栏的基本布局以及不使用任何基本布局的登录功能。

这里我唯一不喜欢的是,每次添加一个使用某些基本布局的新模块时,您都需要为该基本布局修改路由文件,因为这违反了开闭原则。

关于javascript - 在 Angular2 中管理不同的基本布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43469401/

相关文章:

javascript - 我可以通过更改 Angular Js 中的 url 地址来移动到我的个人资料页面而无需登录吗?

javascript - 如何对 Bootstrap 卡进行分页

javascript - 如何在javascript变量上添加换行符

javascript - 来自带有子对象的 json 的 Angularjs ng-options

javascript - 拖动 anchor 绑定(bind) ‘mousedowd, mousemove, mouseup’时如何防止重定向?

twitter-bootstrap-3 - Angular 2 rc4 将组件内容导入模态

Angular 8 : Reactive Form match password

angular - 如何检查多个订阅是否达到onComplete()?

javascript - 无法在 AngularJS 模板中循环数组

javascript - 如何防止页面在表单提交时重新加载,并显示一条小文字 "successfully registered"