raj m
raj m

Reputation: 2023

Router navigation in other page

I have appcomponent, here I have added all the routes. In the next page I have few links. each links will route to same router outlet. How can I navigate on click of tag.

Tried with [routerLink]="['PersonInvolved']". But getting error like "Can't bind to 'routerLink' since it isn't a known native property". Since router and router outlet is defined in first component. And I am linking the router from step1 component.

Upvotes: 1

Views: 229

Answers (1)

Cubicle.Jockey
Cubicle.Jockey

Reputation: 3328

So I am currently having the same issue. I have found a workaround until the issue is resolved. But I notice that my dependency is on router 3.0.0-beta2, so it might be worth upgrading to latest later. I am under a time constraint so here is what I did.

In your ts file for your component where you want the links use dependency injection to get a router object.

//Something like this.
constructor(private router: Router){
}

Then create a function to do the navigation:

navigateSomewhere(){
   this.router.navigate(['yourPage']);
}

Then on your <a> tag do this <a (click)="navigateSomewhere()">Click</a>

Upvotes: 1

Related Questions