Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2 router navigate function not working

Tags:

angular

I have a problem with the router function "navigate", in my AppComponent I have :

@RouteConfig([ 
  {path:'/home', name: 'Home', component: HomeComponent,  useAsDefault: true, data: {user: null}},
  {path:'/dashboard', name: 'Dashboard', component: DashboardComponent}
])

In my HomeComponent, I am trying to do this :

...
constructor(private _router:Router){}

changePage(){
  this._router.parent.navigate(["Dashboard"]); // It fails
}
...

It doesn't send me at '/dashboard', is this normal ?

like image 348
Raph Avatar asked Mar 15 '16 14:03

Raph


3 Answers

I have finally found ! It's working with :

changePage() {
  this._router.navigate(["../Dashboard"]);
}

Thank you for helping me

like image 160
Raph Avatar answered Oct 18 '22 09:10

Raph


why using parent ? it should be this._router.navigate(["Dashboard"]);

like image 24
Michael Desigaud Avatar answered Oct 18 '22 11:10

Michael Desigaud


router.navigate is a method which take path as a parameter and navigate to that particular path and load component, I hope it will work.

constructor(private _router:Router){}
changePage(){
this._router.navigate(["dashboard"]);
}
like image 1
Jainy Avatar answered Oct 18 '22 11:10

Jainy