Skip to content

Commit

Permalink
Merge pull request #2464 from blokfyuh/blokfyuh-hash-fix-permissions-…
Browse files Browse the repository at this point in the history
…plugins

fix(transitionTo): re-added the saved hash before broadcasting event
  • Loading branch information
nateabele committed Jan 19, 2016
2 parents d31b333 + 8c1bf30 commit 2d23875
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 2d23875

Please sign in to comment.