Skip to content

Commit b267ecd

Browse files
fix(): Avoid re-synchronizing from url after .transitionTo
Closes #1573
1 parent 7cfd9d6 commit b267ecd

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/state.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
194194
if (!state[abstractKey] && state.url) {
195195
$urlRouterProvider.when(state.url, ['$match', '$stateParams', function ($match, $stateParams) {
196196
if ($state.$current.navigable != state || !equalForKeys($match, $stateParams)) {
197-
$state.transitionTo(state, $match, { location: false });
197+
$state.transitionTo(state, $match, { inherit: true, location: false });
198198
}
199199
}]);
200200
}
@@ -1075,7 +1075,7 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
10751075

10761076
if (options.location && to.navigable) {
10771077
$urlRouter.push(to.navigable.url, to.navigable.locals.globals.$stateParams, {
1078-
replace: options.location === 'replace'
1078+
$$avoidResync: true, replace: options.location === 'replace'
10791079
});
10801080
}
10811081

src/urlRouter.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ function $UrlRouterProvider( $locationProvider, $urlMatcherFactory) {
265265
$get.$inject = ['$location', '$rootScope', '$injector', '$browser'];
266266
function $get( $location, $rootScope, $injector, $browser) {
267267

268-
var baseHref = $browser.baseHref(), location = $location.url();
268+
var baseHref = $browser.baseHref(), location = $location.url(), lastPushedUrl = undefined;
269269

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

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

350353
push: function(urlMatcher, params, options) {
351354
$location.url(urlMatcher.format(params || {}));
355+
lastPushedUrl = options && options.$$avoidResync ? $location.url() : undefined;
352356
if (options && options.replace) $location.replace();
353357
},
354358

0 commit comments

Comments
 (0)