]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
fix(router): do not restore history when ...
authorEduardo San Martin Morote <posva13@gmail.com>
Sun, 27 Dec 2020 12:49:12 +0000 (13:49 +0100)
committerEduardo San Martin Morote <posva13@gmail.com>
Sun, 27 Dec 2020 12:52:50 +0000 (13:52 +0100)
navigating back or forward and a navigation guard triggers a
redirect

Related to #662

src/router.ts

index 8561d257681ce1ffa002b1a6231e560031b223fd..5dc4279ba478cea711b8f9ad5a1adcf054f05d1c 100644 (file)
@@ -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(