Skip to content

Commit d27a893

Browse files
DickSmithsis0k0
authored andcommitted
fix(router): state is not guarded before use (#1331)
`state` is not guarded before use, but `peekState` may return null. Appears to have been introduced [here](b98da83#diff-a7820fa2a2eb0ce14f3f0b8bfc666dd5R49). Before those changes, `state` was guarded. May result in the following stack, seen on some older iOS devices (2-3 years) when rapidly navigating: ``` CONSOLE ERROR file:///app/tns_modules/@angular/core/bundles/core.umd.js:1682:24: ERROR TypeError: undefined is not an object (evaluating 'state.isPageNavigation') CONSOLE ERROR file:///app/tns_modules/@angular/core/bundles/core.umd.js:1682:24: ERROR TypeError: undefined is not an object (evaluating 'state.isPageNavigation') CONSOLE ERROR file:///app/tns_modules/@angular/core/bundles/core.umd.js:1682:24: ERROR Error: Uncaught (in promise): TypeError: null is not an object (evaluating 'state.isRootSegmentGroup') path@file:///app/tns_modules/nativescript-angular/router/ns-location-strategy.js:33:18 get@file:///app/tns_modules/nativescript-angular/router/ns-platform-location.js:38:46 path@file:///app/tns_modules/@angular/common/bundles/common.umd.js:589:46 path@file:///app/tns_modules/@angular/common/bundles/common.umd.js:247:58 isCurrentPathEqualTo@file:///app/tns_modules/@angular/common/bundles/common.umd.js:260:25 file:///app/tns_modules/@angular/router/bundles/router.umd.js:4158:56 file:///app/tns_modules/rxjs/internal/Observable.js:203:25 __tryOrUnsub@file:///app/tns_modules/rxjs/internal/Subscriber.js:263:20 next@file:///app/tns_modules/rxjs/internal/Subscriber.js:201:34 _next@file:///app/tns_modules/rxjs/internal/Subscriber.js:139:30 next@file:///app/tns_modules/rxjs/internal/Subscriber.js:103:23 _next@file:///app/tns_module ```
1 parent 11d01f9 commit d27a893

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

Diff for: nativescript-angular/router/ns-location-strategy.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,12 @@ export class NSLocationStrategy extends LocationStrategy {
5050
return "/";
5151
}
5252

53-
let tree = this.currentUrlTree;
5453
const state = this.peekState(this.currentOutlet);
54+
if (!state) {
55+
return "/";
56+
}
57+
58+
let tree = this.currentUrlTree;
5559

5660
// Handle case where the user declares a component at path "/".
5761
// The url serializer doesn't parse this url as having a primary outlet.

0 commit comments

Comments
 (0)