Skip to content

Commit

Permalink
fix(router): do not restore history when ...
Browse files Browse the repository at this point in the history
navigating back or forward and a navigation guard triggers a
redirect

Related to #662
  • Loading branch information
posva committed Dec 27, 2020
1 parent d55e51c commit db267be
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit db267be

Please sign in to comment.