Nativescript-angular: Issue with navigating twice with the v3 router

Created on 21 Jun 2016  ·  1Comment  ·  Source: NativeScript/nativescript-angular

Hey,

When I try to navigate twice with the new v3 router I get a “Calling navigateToNewPage while already navigating to new page” error (see full stack trace below).

I need to do a little more testing to see if this is just me. You can try this for yourself on the angular-v3-router branch of Groceries https://github.com/NativeScript/sample-Groceries/tree/angular-v3-router. Log in and then Log Off and you’ll see the problem.

Thanks.

Jun 21 11:36:44 VANTOLLMAC-7 sampleGroceries[8676]: CONSOLE LOG file:///app/tns_modules/@angular/core/src/facade/lang.js:371:16: EXCEPTION: Error: Uncaught (in promise): Error: Calling navigateToNewPage while already navigating to new page.
Jun 21 11:36:44 VANTOLLMAC-7 sampleGroceries[8676]: CONSOLE LOG file:///app/tns_modules/@angular/core/src/facade/lang.js:371:16: STACKTRACE:
Jun 21 11:36:44 VANTOLLMAC-7 sampleGroceries[8676]: CONSOLE LOG file:///app/tns_modules/@angular/core/src/facade/lang.js:371:16: resolvePromise@file:///app/tns_modules/zone.js/dist/zone-node.js:496:41
    file:///app/tns_modules/zone.js/dist/zone-node.js:473:28
    invoke@file:///app/tns_modules/zone.js/dist/zone-node.js:281:34
    onInvoke@file:///app/tns_modules/@angular/core/src/zone/ng_zone_impl.js:46:47
    invoke@file:///app/tns_modules/zone.js/dist/zone-node.js:280:43
    run@file:///app/tns_modules/zone.js/dist/zone-node.js:174:50
    file:///app/tns_modules/zone.js/dist/zone-node.js:529:61
    invokeTask@file:///app/tns_modules/zone.js/dist/zone-node.js:314:43
    onInvokeTask@file:///app/tns_modules/@angular/core/src/zone/ng_zone_impl.js:37:51
    invokeTask@file:///app/tns_modules/zone.js/dist/zone-node.js:313:55
    runTask@file:///app/tns_modules/zone.js/dist/zone-node.js:214:58
    drainMicroTaskQueue@file:///app/tns_modules/zone.js/dist/zone-node.js:432:43
    promiseReactionJob@[native code]
    UIApplicationMain@[native code]
    start@file:///app/tns_modules/application/application.js:233:26
    file:///app/tns_modules/nativescript-angular/application.js:94:26
    ZoneAwarePromise@file:///app/tns_modules/zone.js/dist/zone-node.js:542:38
    nativeScriptBootstrap@file:///app/tns_modules/nativescript-angular/application.js:93:23
    anonymous@file:///app/main.js:7:36
    evaluate@[native code]
    moduleEvaluation@[native code]
    [native code]
    promiseReactionJob@[native code]
Jun 21 11:36:44 VANTOLLMAC-7 sampleGroceries[8676]: CONSOLE ERROR file:///app/tns_modules/zone.js/dist/zone-node.js:419:27: Unhandled Promise rejection: Calling navigateToNewPage while already navigating to new page. ; Zone: angular ; Task: Promise.then ; Value: Error: Calling navigateToNewPage while already navigating to new page.
Jun 21 11:36:44 VANTOLLMAC-7 sampleGroceries[8676]: CONSOLE ERROR file:///app/tns_modules/zone.js/dist/zone-node.js:421:23: Error: Uncaught (in promise): Error: Calling navigateToNewPage while already navigating to new page.

Most helpful comment

Hey @tjvantoll
Found the problem - the NS_ROUTER_PROVIDERS were injected twice - once form inside the AppComponent in your app and one form the nsProvideRouter function. The result - 2 instances of LocationStrategy were created and navigation was messed up.

The solution - there is no need to provide NS_ROUTER_PROVIDERS as they are provided form the nsProvideRouter function - we will update the help and the docs and even consider stop exposing NS_ROUTER_PROVIDERS as you will probably just use nsProvideRouter most of the times.

Here is the PR.

>All comments

Hey @tjvantoll
Found the problem - the NS_ROUTER_PROVIDERS were injected twice - once form inside the AppComponent in your app and one form the nsProvideRouter function. The result - 2 instances of LocationStrategy were created and navigation was messed up.

The solution - there is no need to provide NS_ROUTER_PROVIDERS as they are provided form the nsProvideRouter function - we will update the help and the docs and even consider stop exposing NS_ROUTER_PROVIDERS as you will probably just use nsProvideRouter most of the times.

Here is the PR.

Was this page helpful?
0 / 5 - 0 ratings