Angular 2 loadChildren无法使用canActivateChild

时间:2017-06-16 13:14:11

标签: angular lazy-loading angular-routing

我正在尝试使用Angular2来延迟加载一些模块。我可以使它工作,但当我与canActivateChild一起使用时,它会阻止导航但加载模块,我不知道我是否需要做任何其他事情,但我只想加载模块我是允许访问路线。例如,这是一个管理仪表板,我只想在用户登录时加载AdminModule。

这是我的主要模块路由:

export const routing = [
    { path: '', redirectTo: 'home', pathMatch: 'full' },
    { path: 'login', component: LoginComponent },
    {
        path: '',
        canActivateChild: [AuthGuard],
        children: [
            { path: 'home', component: HomeComponent },
            { path: 'adm', loadChildren: './admin/admin.module#AdminModule' },
        ]
    },
    { path: '**', component: NotFoundComponent },
];

这是我的管理员路由:

export const adminRouting = [
    { path: '',
        children: [
            { path: 'client', component: ClientComponent },
            { path: 'support', component: SupportComponent },
            // more routes
        ]
    },
];

就像我说的那样,导航中的所有内容都按预期工作,但是当我没有登录时,我想阻止加载lazyLoad模块。

1 个答案:

答案 0 :(得分:2)

根据角度的the routing guide,我认为你必须使用canLoad代替canActivate