angular-ui / ui-router

The de-facto solution to flexible routing with nested views in AngularJS
http://ui-router.github.io/
MIT License
13.56k stars 3.01k forks source link

DSR using params subset redirecting to the default state #3770

Closed DavideCordella closed 4 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]);
    }
});

};`

the problem is at following line: 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???

Many thanks everybody.

christopherthielen commented 4 years ago

https://github.com/ui-router/dsr/pull/165