Angular 2 router transition function not working

I have a problem with the "navigate" router function, 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 does not send me to '/ dashboard', is that normal?

+4
source share
5 answers

I finally found! It works with:

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

Thank you for helping me.

+4
source

why use a parent? it should bethis._router.navigate(["Dashboard"]);

+2
source

?

this._router.parent.navigate, this._router.navigate..?

0

, AppComponent:

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

router.navigate is a method that takes a path as a parameter and moves to that particular path and boot component, I hope it works.

constructor(private _router:Router){}
changePage(){
this._router.navigate(["dashboard"]);
}
0
source

All Articles