fix(router): routerLinkActive should only set classes after the router has successfully navigated

This commit is contained in:
vsavkin
2016-07-20 17:51:21 -07:00
parent eb6ff65af7
commit db54a84d14
10 changed files with 69 additions and 4 deletions

View File

@ -94,7 +94,7 @@ export class RouterLinkActive implements OnChanges, OnDestroy, AfterContentInit
ngOnDestroy(): any { this.subscription.unsubscribe(); }
private update(): void {
if (!this.links || !this.linksWithHrefs) return;
if (!this.links || !this.linksWithHrefs || !this.router.navigated) return;
const currentUrlTree = this.router.parseUrl(this.router.url);
const isActiveLinks = this.reduceList(currentUrlTree, this.links);

View File

@ -133,6 +133,13 @@ export class Router {
private config: Routes;
private configLoader: RouterConfigLoader;
/**
* Indicates if at least one navigation happened.
*
* @experimental
*/
navigated: boolean = false;
/**
* Creates the router service.
*/
@ -385,6 +392,7 @@ export class Router {
})
.then(
() => {
this.navigated = true;
this.routerEvents.next(
new NavigationEnd(id, this.serializeUrl(url), this.serializeUrl(appliedUrl)));
resolvePromise(navigationIsSuccessful);