Skip to content

Commit 79d4fd7

Browse files
fix(paramTypes.hash): Update hash for each transition
The hash parameter (`#`) is now a `dynamic: true` param, and equals are compared with coersion, such that "" == undefined == null. Closes #2742
1 parent f9c3e3c commit 79d4fd7

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

src/params/paramTypes.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export class ParamTypes {
2323
decode: valFromString,
2424
is: is(String),
2525
pattern: /.*/,
26-
equals: val(true)
26+
equals: (a, b) => a == b // allow coersion for null/undefined/""
2727
},
2828
"string": {
2929
encode: valToString,

src/state/stateRegistry.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class StateRegistry {
2727
url: '^',
2828
views: null,
2929
params: {
30-
'#': { value: null, type: 'hash' }
30+
'#': { value: null, type: 'hash', dynamic: true }
3131
},
3232
abstract: true
3333
};

test/ng1/stateSpec.js

+15
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,21 @@ describe('state', function () {
663663
expect($location.hash()).toBe('frag');
664664
}));
665665

666+
it('runs a transition when the location #fragment is updated', inject(function ($state, $q, $location, $transitions) {
667+
var transitionCount = 0;
668+
$transitions.onSuccess({}, function() { transitionCount++; });
669+
670+
$state.transitionTo('home.item', {id: 'world', '#': 'frag'});
671+
$q.flush();
672+
expect($location.hash()).toBe('frag');
673+
expect(transitionCount).toBe(1);
674+
675+
$state.transitionTo('home.item', {id: 'world', '#': 'blarg'});
676+
$q.flush();
677+
expect($location.hash()).toBe('blarg');
678+
expect(transitionCount).toBe(2);
679+
}));
680+
666681
it('injects $transition$ into resolves', inject(function ($state, $q) {
667682
$state.transitionTo('home'); $q.flush();
668683
$state.transitionTo('about'); $q.flush();

0 commit comments

Comments
 (0)