@@ -651,6 +651,9 @@ export function createNavigationApiRouter(options: RouterApiOptions): Router {
651651 triggerError ( failure , to , from )
652652 }
653653 throw failure
654+ } finally {
655+ // update always, we'll have some race condition it the user clicks 2 links
656+ pendingLocation = undefined
654657 }
655658 } ,
656659 } )
@@ -696,7 +699,8 @@ export function createNavigationApiRouter(options: RouterApiOptions): Router {
696699 isRevertingNavigation = true
697700 go ( fromIndex - toIndex )
698701
699- afterGuards . list ( ) . forEach ( guard => guard ( to , from , failure ) )
702+ // we end up at from to keep consistency
703+ finalizeNavigation ( from , to , failure )
700704
701705 if ( isNavigationFailure ( failure , ErrorTypes . NAVIGATION_GUARD_REDIRECT ) ) {
702706 navigate ( ( failure as NavigationRedirectError ) . to , { replace : true } )
@@ -705,6 +709,9 @@ export function createNavigationApiRouter(options: RouterApiOptions): Router {
705709 ) {
706710 triggerError ( failure , to , from )
707711 }
712+ } finally {
713+ // update always, we'll have some race condition it the user clicks 2 links
714+ pendingLocation = undefined
708715 }
709716 }
710717
@@ -786,13 +793,25 @@ export function createNavigationApiRouter(options: RouterApiOptions): Router {
786793 ) {
787794 // see above
788795 started = true
789- const initialLocation =
796+ const initialLocation = resolve (
790797 window . location . pathname +
791- window . location . search +
792- window . location . hash
793- navigate ( initialLocation ) . catch ( err => {
794- if ( __DEV__ ) warn ( 'Unexpected error when starting the router:' , err )
795- } )
798+ window . location . search +
799+ window . location . hash
800+ ) as RouteLocationNormalized
801+ resolveNavigationGuards ( initialLocation , START_LOCATION_NORMALIZED )
802+ . then ( ( ) => {
803+ finalizeNavigation ( initialLocation , START_LOCATION_NORMALIZED )
804+ } )
805+ . catch ( err => {
806+ if (
807+ isNavigationFailure ( err , ErrorTypes . NAVIGATION_GUARD_REDIRECT )
808+ ) {
809+ navigate ( err . to , { replace : true } )
810+ } else {
811+ if ( __DEV__ )
812+ warn ( 'Unexpected error when starting the router:' , err )
813+ }
814+ } )
796815 }
797816
798817 const reactiveRoute = { } as RouteLocationNormalizedLoaded
0 commit comments