Meakyl
Meakyl

Reputation: 43

Cannot match any routes angular 2.0.1

I have a problem with my plunkr. http://plnkr.co/edit/70ZFRPJdAraDDV8heMlo?p=preview

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

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

I can't simply do a router.navigate. I have the error :

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

Everything looks ok to me. Related to Cannot match any routes: '' but I don't have any children routes.

Thanks

Upvotes: 4

Views: 814

Answers (2)

danday74
danday74

Reputation: 56936

no slash before the path and brackets ...

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

Upvotes: 0

Günter Zöchbauer
Günter Zöchbauer

Reputation: 657068

Add []

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

or use navigateByUrl()

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

Plunker example

Upvotes: 2

Related Questions