2016-11-07 100 views
3

我的plunkr有問題。 http://plnkr.co/edit/70ZFRPJdAraDDV8heMlo?p=preview角度不匹配任何路線2.0.1

const routes = [ 
    {path: 'test', component: Test}, 
    {path: 'home', component: HomeComponent}, 
    {path: '', redirectTo: 'home', pathMatch: "full"} 
]; 

this.router.navigate('/test'); 

我不能簡單地做一個router.navigate。我有錯誤:

Error: Cannot match any routes. URL Segment: 't/e/s/t'

一切看起來都對我好。 與Cannot match any routes: ''相關,但我沒有任何兒童路線。

感謝

回答

2

添加[]

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

或使用

this.router.navigateByUrl('/test'); 

Plunker example

+0

非常感謝就是這樣。 – Meakyl

0

路徑和括號前沒有斜槓...

this.router.navigate(['test']);