2016-11-10 71 views
1
另一頁

我在角2個新的,我使用的NG2 - 管理模板這是在角2.0.0版本。 我想航線從組件我的網頁一樣,如果用戶成功登錄,然後路由到儀表板page.Currently我使用「route.navigate([‘儀表板’])」 但之後調用函數它給了我像不確定的錯誤路線。 以下是組件端代碼: enter image description here無法從頁分量的路徑來

我module.ts文件 enter image description here

我的登錄路由組件是: enter image description here

和主路由組件是: enter image description here

請幫我,謝謝

+0

郵政路由組件還,錯誤指出,這條路線是缺少。 –

回答

2

你將不得不import { RouterModule, Routes } from '@angular/router';,然後你會做你的app.tsmain.ts如下聲明你的路由:

const routes: Routes = [ 
    { path: '', redirectTo: '/dashboard', pathMatch: 'full' }, 
    { path: 'dashboard', component: DashboardComponent }, 
]; 
@NgModule({ 
    imports: [ RouterModule.forRoot(routes) ], 
    exports: [ RouterModule ] 
}) 

然後你可以在相應的組件使用routes象下面這樣:

this.router.navigate(['/dashboard']); 

添加新function

gotoDashBoard() { 
    console.log("coming"); 
    console.log(this); 
    this.router.navigate(['/dashboard']); 
} 

call這在你的response => {this.gotoCrises()}

+1

如果他在路由組件宣佈他們,你不需要在app.module –

+1

@AvramVirgil再次聲明他們:同意...我想在OP已經錯過了... – Thalaivar

+0

@RohitDeshmukh:有沒有幫助? – Thalaivar