2017-02-27 133 views
0

我想在應用程序組件html中創建一個包含登錄信息的頁面,然後,當用戶登錄時,我想轉到另一個視圖,可以是:儀表板,並在儀表板顯示導航菜單。Angular 2:router not in app component

我該怎麼做才能正確?

我可以把標籤

<router-outlet></router-outlet> 

在這種app.component,使它的工作原理不同的充看法?

謝謝你!

+1

https://angular.io/docs/ts/latest/guide/router.html –

回答

1

您應該爲此使用路由器防護。

Here is a great article about protecting routes

隨着如果我去/儀表板,我沒有登錄,我會登錄頁面後,我登錄,我可以去你能保護某些路線在您的應用程序,例如保護到/儀表板路線。

+0

聽起來不錯,讓我檢查。 –

1

那麼,在app.module.ts你必須輸入路由器模塊,以及:

import { RouterModule } from '@angular/router'; 

,並在進口-section需要有像

RouterModule.forRoot(ROUTES), 

中,路由一條線您的路由信息​​的定義,例如

const ROUTES = [ 
    { 
    path: 'videos', 
    component: VideosComponent, 
    } 
];