christopherthielen / ui-router-extras

THIS PROJECT IS NO LONGER MAINTAINED -- Extras for UI-Router for AngularJS. Sticky States (a.k.a. parallel states), Deep State Redirect (for tab-like navigation), Future States (async state definition)
http://christopherthielen.github.io/ui-router-extras/
MIT License
917 stars 211 forks source link

DSR Navigation not correctly stopped #377

Open DavideCordella opened 6 years ago

DavideCordella commented 6 years ago

Dear All, I can see that when we trigger a navigation to a root state A and DSR towards its child status B is enabled, the initial navigation to A is not "fully stopped" but for some reason it continues even if redirection to B has been trigger.

I believe the problem is at the end of this callback:

`$rootScope.$on("$stateChangeStart", function (event, toState, toParams, fromState, fromParams) { var cfg = getConfig(toState); if (ignoreDsr || (computeDeepStateStatus(toState) !== REDIRECT) && !cfg['default']) return; // We're changing directly to one of the redirect (tab) states. // Get the DSR key for this state by calculating the DSRParams option var key = getParamsString(toParams, cfg.params); var redirect = lastSubstate[toState.name][key] || cfg['default']; if (!redirect) return;

// we have a last substate recorded
var $dsr$ = { redirect: { state: redirect.state, params: redirect.params}, to: { state: toState.name, params: toParams } };
var result = $injector.invoke(cfg.fn, toState, { $dsr$: $dsr$ });
if (!result) return;
if (result.state) redirect = result;
event.preventDefault();
var redirectParams = getMatchParams(toParams, cfg.params);
**setTimeout(function () { $state.go(redirect.state, angular.extend(redirectParams, redirect.params)); }, 100)**

});`

if I set a timeout on calling the redirection, the initial navigation is correctly stopped and the redirection correctly happend after it.

Can anybody advise? Can we push this change?

Thanks everybody