From bbad42310b6ba4df803917fa9b32e1e702eca531 Mon Sep 17 00:00:00 2001 From: Andrew Scott Date: Mon, 9 Aug 2021 09:00:48 -0700 Subject: [PATCH] fix(router): ensure check for match options is compatible with property renaming (#43086) After renaming, 'paths' is not in routerLinkOptions since it's been renamed. PR Close #43086 --- packages/router/src/directives/router_link_active.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/router/src/directives/router_link_active.ts b/packages/router/src/directives/router_link_active.ts index 8670469a7f..257437f37d 100644 --- a/packages/router/src/directives/router_link_active.ts +++ b/packages/router/src/directives/router_link_active.ts @@ -168,7 +168,8 @@ export class RouterLinkActive implements OnChanges, OnDestroy, AfterContentInit } private isLinkActive(router: Router): (link: (RouterLink|RouterLinkWithHref)) => boolean { - const options = 'paths' in this.routerLinkActiveOptions ? + const options: boolean|IsActiveMatchOptions = + isActiveMatchOptions(this.routerLinkActiveOptions) ? this.routerLinkActiveOptions : // While the types should disallow `undefined` here, it's possible without strict inputs (this.routerLinkActiveOptions.exact || false); @@ -182,3 +183,11 @@ export class RouterLinkActive implements OnChanges, OnDestroy, AfterContentInit this.links.some(isActiveCheckFn) || this.linksWithHrefs.some(isActiveCheckFn); } } + +/** + * Use instead of `'paths' in options` to be compatible with property renaming + */ +function isActiveMatchOptions(options: {exact: boolean}| + IsActiveMatchOptions): options is IsActiveMatchOptions { + return !!(options as IsActiveMatchOptions).paths; +}