Reputation: 21
I am building a testportal where students can give test,so on OnInit
of TestComponent
.I get the complete test from a service and then route to the questions or the instruction component depending upon the state of test(paused or starting for the first time).
It is not working there,even though the promise returned by this.router.navigate
is resolving,If I put my this.router.navigate
code in a settimeout
,even with a timeout of 0 it works and navigates properly.
Any help on how to handle this case and details on why it is not navigating properly,I looked at the router's code but could not seem to find anything there. This is from angular2 final release.
TL;DR
this.route .navigate
is not working on the OnInit
of component.
@angular/router: 3.0.0
@angular/common: 2.0.0
Upvotes: 1
Views: 543
Reputation: 21
RouterModule.forRoot(appRoutes, { initialNavigation: false });
My issue was because,I was trying to navigate to a different url,before inital navigation was over.Putting this line in app.routing.ts solved the issue.
https://github.com/angular/angular/issues/11748
Upvotes: 1