From db267be72bace7c99a0c65669ab04ce770e1532c Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Sun, 27 Dec 2020 13:49:12 +0100 Subject: [PATCH] fix(router): do not restore history when ... navigating back or forward and a navigation guard triggers a redirect Related to #662 --- src/router.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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( -- 2.39.5