如果条件,角度2/5路线

时间:2018-02-27 13:02:44

标签: angular routing

我尝试构建一个简单的解决方案,用于管理哪些页面可供用户使用,而这些页面尚未插入。 我希望只有那些痴迷的人才能在我的网站上做点什么。所有不是的人都应该被重定向到登录页面。为此,我实现了创建路线的if条件:

var myRoutes: Routes;
if (!localStorage.getItem('currentUser')) {      
    myRoutes = [
        {path: 'login', component: ProfileComponent},
        {path: '**', redirectTo: '/login'}
    ];
} else {
    const myRoutes = [
        {path: 'profile', component: ProfileComponent},
        {path: 'settings', component: SettingsComponent},
        {path: 'home', component: HomeComponent},
        {path: '**', redirectTo: '/home'}
    ];
}

如果我使用ng服务一切正常。但是,如果我尝试通过ng build构建应用程序,则会出现以下错误:

  

TypeError中的错误:无法读取未定义的属性“loadChildren”

为什么不起作用?可能有不同的解决方案吗?

0 个答案:

没有答案
相关问题