From: Eduardo San Martin Morote Date: Sun, 27 Dec 2020 12:49:12 +0000 (+0100) Subject: fix(router): do not restore history when ... X-Git-Tag: v4.0.2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=db267be72bace7c99a0c65669ab04ce770e1532c;p=thirdparty%2Fvuejs%2Frouter.git fix(router): do not restore history when ... navigating back or forward and a navigation guard triggers a redirect Related to #662 --- diff --git a/src/router.ts b/src/router.ts index 8561d257..5dc4279b 100644 --- a/src/router.ts +++ b/src/router.ts @@ -934,8 +934,14 @@ export function createRouter(options: RouterOptions): Router { if ( isNavigationFailure(error, ErrorTypes.NAVIGATION_GUARD_REDIRECT) ) { - // do not restore history on unknown direction - if (info.delta) routerHistory.go(-info.delta, false) + // Here we could call if (info.delta) routerHistory.go(-info.delta, + // false) but this is bug prone as we have no way to wait the + // navigation to be finished before calling pushWithRedirect. Using + // a setTimeout of 16ms seems to work but there is not guarantee for + // it to work on every browser. So Instead we do not restore the + // history entry and trigger a new navigation as requested by the + // navigation guard. + // the error is already handled by router.push we just want to avoid // logging the error pushWithRedirect(