Skip to content

Commit

Permalink
fix(): Avoid re-synchronizing from url after .transitionTo
Browse files Browse the repository at this point in the history
Closes #1573
  • Loading branch information
christopherthielen committed Nov 20, 2014
1 parent 7cfd9d6 commit b267ecd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
if (!state[abstractKey] && state.url) {
$urlRouterProvider.when(state.url, ['$match', '$stateParams', function ($match, $stateParams) {
if ($state.$current.navigable != state || !equalForKeys($match, $stateParams)) {
$state.transitionTo(state, $match, { location: false });
$state.transitionTo(state, $match, { inherit: true, location: false });
}
}]);
}
Expand Down Expand Up @@ -1075,7 +1075,7 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {

if (options.location && to.navigable) {
$urlRouter.push(to.navigable.url, to.navigable.locals.globals.$stateParams, {
replace: options.location === 'replace'
$$avoidResync: true, replace: options.location === 'replace'
});
}

Expand Down
6 changes: 5 additions & 1 deletion src/urlRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ function $UrlRouterProvider( $locationProvider, $urlMatcherFactory) {
$get.$inject = ['$location', '$rootScope', '$injector', '$browser'];
function $get( $location, $rootScope, $injector, $browser) {

var baseHref = $browser.baseHref(), location = $location.url();
var baseHref = $browser.baseHref(), location = $location.url(), lastPushedUrl = undefined;

function appendBasePath(url, isHtml5, absolute) {
if (baseHref === '/') return url;
Expand All @@ -277,6 +277,9 @@ function $UrlRouterProvider( $locationProvider, $urlMatcherFactory) {
// TODO: Optimize groups of rules with non-empty prefix into some sort of decision tree
function update(evt) {
if (evt && evt.defaultPrevented) return;
if (lastPushedUrl && $location.url() === lastPushedUrl)
return lastPushedUrl = undefined;
lastPushedUrl = undefined;

function check(rule) {
var handled = rule($injector, $location);
Expand Down Expand Up @@ -349,6 +352,7 @@ function $UrlRouterProvider( $locationProvider, $urlMatcherFactory) {

push: function(urlMatcher, params, options) {
$location.url(urlMatcher.format(params || {}));
lastPushedUrl = options && options.$$avoidResync ? $location.url() : undefined;
if (options && options.replace) $location.replace();
},

Expand Down

0 comments on commit b267ecd

Please sign in to comment.