Created
April 25, 2018 04:43
-
-
Save gerich-home/3065d97839c729b49fcbf9c0ff39d9af to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
router.umd.js | 30 ++++++++++++++++++++---------- | |
1 file changed, 20 insertions(+), 10 deletions(-) | |
diff --git a/router.umd.js b/router.umd.js | |
index f5eb9398..e0fd1e12 100644 | |
--- a/router.umd.js | |
+++ b/router.umd.js | |
@@ -4020,7 +4020,7 @@ var Router = (function () { | |
// If the user triggers a navigation imperatively (e.g., by using navigateByUrl), | |
// and that navigation results in 'replaceState' that leads to the same URL, | |
// we should skip those. | |
- if (lastNavigation && source !== 'imperative' && lastNavigation.source === 'imperative' && | |
+ if (lastNavigation && source !== 'imperative' && lastNavigation.source === 'imperative' && lastNavigation.isSuccessful && | |
lastNavigation.rawUrl.toString() === rawUrl.toString()) { | |
return Promise.resolve(true); // return value is not used | |
} | |
@@ -4049,13 +4049,13 @@ var Router = (function () { | |
*/ | |
Router.prototype.executeScheduledNavigation = function (_a) { | |
var _this = this; | |
- var id = _a.id, rawUrl = _a.rawUrl, extras = _a.extras, resolve = _a.resolve, reject = _a.reject; | |
+ var id = _a.id, rawUrl = _a.rawUrl, extras = _a.extras, source = _a.source, reject = _a.reject; | |
var /** @type {?} */ url = this.urlHandlingStrategy.extract(rawUrl); | |
var /** @type {?} */ urlTransition = !this.navigated || url.toString() !== this.currentUrlTree.toString(); | |
if (urlTransition && this.urlHandlingStrategy.shouldProcessUrl(rawUrl)) { | |
this.routerEvents.next(new NavigationStart(id, this.serializeUrl(url))); | |
Promise.resolve() | |
- .then(function (_) { return _this.runNavigate(url, rawUrl, !!extras.skipLocationChange, !!extras.replaceUrl, id, null); }) | |
+ .then(function (_) { return _this.runNavigate(source, url, rawUrl, !!extras.skipLocationChange, !!extras.replaceUrl, id, null); }) | |
.then(resolve, reject); | |
// we cannot process the current URL, but we could process the previous one => | |
// we need to do some cleanup | |
@@ -4064,13 +4064,22 @@ var Router = (function () { | |
this.urlHandlingStrategy.shouldProcessUrl(this.rawUrlTree)) { | |
this.routerEvents.next(new NavigationStart(id, this.serializeUrl(url))); | |
Promise.resolve() | |
- .then(function (_) { return _this.runNavigate(url, rawUrl, false, false, id, createEmptyState(url, _this.rootComponentType).snapshot); }) | |
+ .then(function (_) { return _this.runNavigate(source, url, rawUrl, false, false, id, createEmptyState(url, _this.rootComponentType).snapshot); }) | |
.then(resolve, reject); | |
} | |
else { | |
this.rawUrlTree = rawUrl; | |
resolve(null); | |
} | |
+ | |
+ function resolve (isSuccessfulNavigation) { | |
+ if (isSuccessfulNavigation) { | |
+ _this.lastSuccessfulNavigationPath = _this.location.path(true); | |
+ _a.isSuccessful = true; | |
+ } | |
+ | |
+ _a.resolve(isSuccessfulNavigation); | |
+ } | |
}; | |
/** | |
* @param {?} url | |
@@ -4081,7 +4090,7 @@ var Router = (function () { | |
* @param {?} precreatedState | |
* @return {?} | |
*/ | |
- Router.prototype.runNavigate = function (url, rawUrl, shouldPreventPushState, shouldReplaceUrl, id, precreatedState) { | |
+ Router.prototype.runNavigate = function (source, url, rawUrl, shouldPreventPushState, shouldReplaceUrl, id, precreatedState) { | |
var _this = this; | |
if (id !== this.navigationId) { | |
this.location.go(this.urlSerializer.serialize(this.currentUrlTree)); | |
@@ -4192,13 +4201,13 @@ var Router = (function () { | |
resolvePromise(true); | |
} | |
else { | |
- _this.resetUrlToCurrentUrlTree(); | |
+ _this.resetUrlToCurrentUrlTree(source); | |
_this.routerEvents.next(new NavigationCancel(id, _this.serializeUrl(url), '')); | |
resolvePromise(false); | |
} | |
}, function (e) { | |
if (isNavigationCancelingError(e)) { | |
- _this.resetUrlToCurrentUrlTree(); | |
+ _this.resetUrlToCurrentUrlTree(source); | |
_this.navigated = true; | |
_this.routerEvents.next(new NavigationCancel(id, _this.serializeUrl(url), e.message)); | |
resolvePromise(false); | |
@@ -4222,9 +4231,10 @@ var Router = (function () { | |
/** | |
* @return {?} | |
*/ | |
- Router.prototype.resetUrlToCurrentUrlTree = function () { | |
- var /** @type {?} */ path = this.urlSerializer.serialize(this.rawUrlTree); | |
- this.location.replaceState(path); | |
+ Router.prototype.resetUrlToCurrentUrlTree = function (source) { | |
+ if (source === 'popstate') { | |
+ this.location.go(this.lastSuccessfulNavigationPath || this.urlSerializer.serialize(this.rawUrlTree)); | |
+ } | |
}; | |
return Router; | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment