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 using params subset redirecting to the default state #382

Open DavideCordella opened 5 years ago

DavideCordella commented 5 years ago

Dear All, I have one root state with a parameter and two substates with the following config: rootState1, /rootstate1/:rootstate1param, params: [rootstate1param] rootState2, /rootstate2/:rootstate2param sub1, rootState1.sub1, /sub1, default sub2, rootState1.sub2 /sub2/:sub2param

The DSR on rootState1 is configured to consider only rootstate1param. If I first access sub1 state and then sub2 when I switch from rootState1 to rootState2 and I come back to rootState1 I get redirected to sub1 instead of sub2 like I'd expect being the last accessed state.

I think the issue is in the following function:

` DSRPlugin.prototype.recordDeepState = function (transition, state) {

         var _this = this;
        var $state = this.$state;
        var hasParamsConfig = !!this.getConfig(state).params;
        var _state = state.$$state();
        transition.promise.then(function () {
            var transTo = transition.to();
            var triggerParams = transition.params();
            var target = $state.target(transTo, triggerParams);
            var targetStateName = target.name();
            var targetParams = target.params();
            var recordedDSR = { triggerParams: triggerParams, targetStateName: targetStateName, targetParams: targetParams };
            if (hasParamsConfig) {
                var currentDSRS = _this.dataStore.get(_state);
                var predicate = _this.paramsEqual(transTo.$$state(), triggerParams, undefined, true);
                var updatedDSRS = currentDSRS.filter(predicate).concat(recordedDSR);
                _this.dataStore.set(_state, updatedDSRS);
            }
            else {
                _this.dataStore.set(_state, [recordedDSR]);
            }
        });
    };`

triggerParams match targetParams and that's not correct when using a subset of the parameters of the target state.

Can you advise?

Many thanks everybody.

DavideCordella commented 5 years ago

I found the problem var predicate = _this.paramsEqual(transTo.$$state(), triggerParams, undefined, true);

insted of passing undefined as 3rd param of paramsEqual we should pass this.getConfig(state).params

Shall I forward a pull request in order to have it fixed???

DavideCordella commented 5 years ago

I found the problem var predicate = _this.paramsEqual(transTo.$$state(), triggerParams, undefined, true);

insted of passing undefined as 3rd param of paramsEqual we should pass this.getConfig(state).params

Shall I forward a pull request in order to have it fixed???