Skip to content

Commit

Permalink
fix(transitionTo): re-added the saved hash before broadcasting event
Browse files Browse the repository at this point in the history
Re-added the saved hash before broadcasting $stateChangeStart. This way, libraries using this event to do their magic will have the hash accessible through toParams. (e.g. https://github.com/Narzerus/angular-permission)
  • Loading branch information
blokfyuh committed Jan 19, 2016
1 parent d31b333 commit 8c1bf30
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,10 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {

// Filter parameters before we pass them to event handlers etc.
toParams = filterByKeys(to.params.$$keys(), toParams || {});


// Re-add the saved hash before we start returning things or broadcasting $stateChangeStart
if (hash) toParams['#'] = hash;

// Broadcast start event and cancel the transition if requested
if (options.notify) {
/**
Expand Down Expand Up @@ -1126,9 +1129,6 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
}
}

// Re-add the saved hash before we start returning things
if (hash) toParams['#'] = hash;

// Run it again, to catch any transitions in callbacks
if ($state.transition !== transition) return TransitionSuperseded;

Expand Down
12 changes: 12 additions & 0 deletions test/stateSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,18 @@ describe('state', function () {
expect($location.url()).toBe('/front/world#frag');
expect($location.hash()).toBe('frag');
}));

it('has access to the #fragment in $stateChangeStart hook', inject(function ($state, $q, $location, $rootScope) {
var hash_accessible = false;
$rootScope.$on('$stateChangeStart', function (event, toState, toParams, fromState, fromParams) {
hash_accessible = toParams['#'] === 'frag';
});

$state.transitionTo('home.item', {id: 'world', '#': 'frag'});
$q.flush();

expect(hash_accessible).toBe(true);
}));
});

describe('.go()', function () {
Expand Down

0 comments on commit 8c1bf30

Please sign in to comment.