在角度2中使用多个路由器

时间:2017-05-23 10:03:08

标签: angular angular-ui-router angular2-forms

 <app-menu></app-menu>
 <app-menu2></app-menu2>
 <router-outlet></router-outlet>
<app-footer></app-footer>

需要一些逻辑,我有两个名为<app-menu><app-menu2>的路由器。

我正在开发一个登录的应用程序。登录后,我想只看到<app-menu2>

现在显示两个菜单。我希望在登录前显示<app-menu>,在登录后显示<app-menu2>。我会记录一些逻辑。

我试图隐藏这个appmenus。那不行。请尽快给我建议。

2 个答案:

答案 0 :(得分:1)

我认为您应该查看身份验证的工作方式,并尝试创建一个正确处理的服务。服务完成后,您应该有一个方法.logged(),然后您可以在组件中使用它。

实际上您的服务非常不安全,您实际上正在加载所有用户并在客户端内检查密码,任何知识渊博的人都应该能够绕过登录。

我建议你看看: https://auth0.com/blog/angular-2-authentication/ 在: http://jasonwatmore.com/post/2016/08/16/angular-2-jwt-authentication-example-tutorial

答案 1 :(得分:1)

您应该使用2个不同的页面/模板,一个用于authed,另一个用于非authed。

请参阅:https://angular.io/docs/ts/latest/guide/router.html

    { 
        path: 'Login', 
        component: LoginComponent,
    }
    {
        path: 'Authed',
        component: YourLoggedInComponent
        children: [
            {
                path: '',
                component: ChildComponent,


            }
        ]
    }
相关问题