Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular4 - routerLink with typescript

I have worked with routerLink and it works very well :

      <a routerLink="inscription" class="btn btn-default">Inscription</a>
      <a routerLink="login" class="btn btn-default">Se connecter</a>

I am trying now to deal with routerLink inside the typescript file. Exactly, when i click on a button, i call a function inside this function i want to call routerLink how could i do it? and if is calling it will reload the page or it will work exactly the same as the routerLink above ?

like image 480
ussefshahid Avatar asked Aug 11 '17 00:08

ussefshahid


3 Answers

In code, you use .navigate instead:

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

You pass it the same parameter as you do the routerLink.

enter image description here

like image 106
DeborahK Avatar answered Oct 19 '22 11:10

DeborahK


try this

<a javascript:void(0) routerLink="inscription" class="btn btn-default">Inscription</a>
like image 41
Jorawar Singh Avatar answered Oct 19 '22 10:10

Jorawar Singh


Please note that though the URL in the browser is not case sensitive, Router.navigate is.

Correct: this.router.navigate(['/products']);.

Incorrect: this.router.navigate(['/Products']);

like image 1
Aaron Hodgson Avatar answered Oct 19 '22 12:10

Aaron Hodgson