fix(router): RouterLinkActive should update its state right after checking the children (#19449)
Closes #18983 PR Close #19449
This commit is contained in:
@ -118,21 +118,19 @@ export class RouterLinkActive implements OnChanges,
|
||||
|
||||
private update(): void {
|
||||
if (!this.links || !this.linksWithHrefs || !this.router.navigated) return;
|
||||
const hasActiveLinks = this.hasActiveLinks();
|
||||
|
||||
// react only when status has changed to prevent unnecessary dom updates
|
||||
if (this.isActive !== hasActiveLinks) {
|
||||
this.classes.forEach((c) => {
|
||||
if (hasActiveLinks) {
|
||||
this.renderer.addClass(this.element.nativeElement, c);
|
||||
} else {
|
||||
this.renderer.removeClass(this.element.nativeElement, c);
|
||||
}
|
||||
});
|
||||
Promise.resolve(hasActiveLinks).then(active => (this as{
|
||||
isActive: boolean
|
||||
}).isActive = active);
|
||||
}
|
||||
Promise.resolve().then(() => {
|
||||
const hasActiveLinks = this.hasActiveLinks();
|
||||
if (this.isActive !== hasActiveLinks) {
|
||||
(this as any).isActive = hasActiveLinks;
|
||||
this.classes.forEach((c) => {
|
||||
if (hasActiveLinks) {
|
||||
this.renderer.addClass(this.element.nativeElement, c);
|
||||
} else {
|
||||
this.renderer.removeClass(this.element.nativeElement, c);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private isLinkActive(router: Router): (link: (RouterLink|RouterLinkWithHref)) => boolean {
|
||||
|
Reference in New Issue
Block a user