@@ -79,7 +79,6 @@ export function createNavigationApiRouter(options: RouterApiOptions): Router {
7979 START_LOCATION_NORMALIZED
8080 )
8181
82- let initialNavigation = true
8382 let isRevertingNavigation = false
8483 let pendingLocation : RouteLocation | undefined
8584 let lastSuccessfulLocation : RouteLocationNormalizedLoaded =
@@ -215,6 +214,7 @@ export function createNavigationApiRouter(options: RouterApiOptions): Router {
215214 from : RouteLocationNormalizedLoaded ,
216215 failure ?: NavigationFailure
217216 ) {
217+ pendingLocation = undefined
218218 if ( ! failure ) {
219219 lastSuccessfulLocation = to
220220 }
@@ -259,10 +259,6 @@ export function createNavigationApiRouter(options: RouterApiOptions): Router {
259259 }
260260
261261 function go ( delta : number ) {
262- if ( delta === 0 && isRevertingNavigation ) {
263- return
264- }
265-
266262 // Case 1: go(0) should trigger a reload.
267263 if ( delta === 0 ) {
268264 window . navigation . reload ( )
@@ -605,20 +601,19 @@ export function createNavigationApiRouter(options: RouterApiOptions): Router {
605601 async function handleNavigate ( event : NavigateEvent ) {
606602 if ( ! event . canIntercept ) return
607603
608- if ( initialNavigation ) {
609- initialNavigation = false
610- return
611- }
612-
613604 event . intercept ( {
614605 async handler ( ) {
615- const destination = new URL ( event . destination . url )
616- const pathWithSearchAndHash =
617- destination . pathname + destination . search + destination . hash
618- const to = resolve ( pathWithSearchAndHash ) as RouteLocationNormalized
619- const from = currentRoute . value
606+ if ( ! pendingLocation ) {
607+ const destination = new URL ( event . destination . url )
608+ const pathWithSearchAndHash =
609+ destination . pathname + destination . search + destination . hash
610+ pendingLocation = resolve (
611+ pathWithSearchAndHash
612+ ) as RouteLocationNormalized
613+ }
620614
621- pendingLocation = to
615+ const to = pendingLocation
616+ const from = currentRoute . value
622617
623618 let navigationInfo : NavigationInformation | undefined
624619 if ( event . navigationType === 'traverse' ) {
@@ -722,9 +717,6 @@ export function createNavigationApiRouter(options: RouterApiOptions): Router {
722717 finalizeNavigation ( to , from )
723718 } catch ( error ) {
724719 const failure = error as NavigationFailure
725- if ( isNavigationFailure ( failure , ErrorTypes . NAVIGATION_DUPLICATED ) ) {
726- return
727- }
728720
729721 isRevertingNavigation = true
730722 go ( event . from . index - window . navigation . currentEntry ! . index )
@@ -823,32 +815,13 @@ export function createNavigationApiRouter(options: RouterApiOptions): Router {
823815 ) {
824816 // see above
825817 started = true
826- const initialLocation = resolve (
818+ const initialLocation =
827819 window . location . pathname +
828- window . location . search +
829- window . location . hash
830- ) as RouteLocationNormalized
831- pendingLocation = initialLocation
832- resolveNavigationGuards ( initialLocation , START_LOCATION_NORMALIZED )
833- . then ( ( ) => {
834- finalizeNavigation ( initialLocation , START_LOCATION_NORMALIZED )
835- } )
836- . catch ( err => {
837- const failure = err as NavigationFailure
838- if (
839- isNavigationFailure ( failure , ErrorTypes . NAVIGATION_GUARD_REDIRECT )
840- ) {
841- return navigate ( ( failure as NavigationRedirectError ) . to , {
842- replace : true ,
843- } )
844- } else {
845- return triggerError (
846- failure ,
847- initialLocation ,
848- START_LOCATION_NORMALIZED
849- )
850- }
851- } )
820+ window . location . search +
821+ window . location . hash
822+ navigate ( initialLocation ) . catch ( err => {
823+ if ( __DEV__ ) warn ( 'Unexpected error when starting the router:' , err )
824+ } )
852825 }
853826
854827 const reactiveRoute = { } as RouteLocationNormalizedLoaded
0 commit comments