NativeScript / nativescript-angular

Integrating NativeScript with Angular
http://docs.nativescript.org/angular/tutorial/ng-chapter-0
Apache License 2.0
1.21k stars 241 forks source link

Angular routes with custom Resolve crashes the application if using the Back button #665

Open darind opened 7 years ago

darind commented 7 years ago

I have a simple nativescript application with 3 routes:

const routes: Routes = [
    { path: "", redirectTo: "/route1", pathMatch: "full" },
    { path: "route1", component: Route1Component },
    { path: "route2", component: Route2Component, resolve: { test: TestResolve } },
    { path: "route3", component: Route3Component }
];

where TestResolve is defined like this:

import { Injectable } from "@angular/core";
import { Resolve } from "@angular/router";

@Injectable()
export class TestResolve implements Resolve<string> {
    resolve() {
        return new Promise((resolve, reject) => {
            setTimeout(function() {
                resolve('we are done here');
            }, 3000);
        });
    }
}

Now I navigate from route1 to route2 and finally route3 within my application using simple links in the corresponding markup:

<Button [nsRouterLink]="['/route2']" text="go to route 2"></Button>

On route3 clicking the Back button multiple times quickly will crash the application with the following:

JS: EXCEPTION: Calling startGoBack while going back.
JS: ORIGINAL STACKTRACE:
JS: Error: Calling startGoBack while going back.
JS:     at NSLocationStrategy._beginBackPageNavigation (file:///data/data/org.nativescript.repro2/files/app/tns_modules/nativescript-angular/router/ns-location-strategy.js:129:19)
JS:     at Object.<anonymous> (file:///data/data/org.nativescript.repro2/files/app/tns_modules/nativescript-angular/router/page-router-outlet.js:189:40)
JS:     at ZoneDelegate.invoke (file:///data/data/org.nativescript.repro2/files/app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:190:28)
JS:     at Object.onInvoke (file:///data/data/org.nativescript.repro2/files/app/tns_modules/@angular/core/bundles/core.umd.js:4391:41)
JS:     at ZoneDelegate.invoke (file:///data/data/org.nativescript.repro2/files/app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:189:34)
JS:     at Zone.runGuarded (file:///data/data/org.nativescript.repro2/files/app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:97:47)
JS:     at Object.callback (file:///data/data/org.nativescript.repro2/files/app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:73:29)
JS:     at Page.Observable.notify (file:///data/data/org.nativescript.repro2/files/app/tns_modules/tns-core-modules/data/observable/observable.js:149:23)
JS:     at Page.onNavigatedFrom (file:///data/data/org.nativescript.repro2/files/app/tns_modules/tns-core-modules/ui/page/page-common.js:234:14)
JS:     at Page.onNavigatedFrom (file:///data/data/org.nativescript.repro2/files/app/tns_modules/tns-core-modules/ui/page/page.js:131:42)
tsonevn commented 7 years ago

Hi @darind, Thank you for reporting this issue. I reviewed this case, unfortunately, I have to confirm that this is a real issue for both iOS and Android. The problem could be reproduced, when we navigate to the latest available Page and then navigate back to the main component. I am attaching sample project. Archive.zip

Regards, @tsonevn

yyosifov commented 7 years ago

Hi @darind @tsonevn,

Unfortunately, after we removed the usage of Resolve throughout our Application, it still crashes with the same error in our app, after navigating several times back and it reaches the Main component.

Just to let you know that the problem is not only when you use a "slow" Resolve function in the routing.

vmachuca commented 6 years ago

updates for this issue?

tsonevn commented 6 years ago

Hi @vmachuca This issue is still under review. At this point, we could not commit to the exact time when the fix will be available.

bradseefeld commented 6 years ago

Any clarity on timeline now? I am seeing this issue occur rather frequently in my production application. We are not using resolve. Just simple path and component.