@@ -78,6 +78,7 @@ export function createNavigationApiRouter(options: RouterApiOptions): Router {
78
78
START_LOCATION_NORMALIZED
79
79
)
80
80
81
+ let initialNavigation = true
81
82
let isRevertingNavigation = false
82
83
let pendingLocation : RouteLocation | undefined
83
84
let lastSuccessfulLocation : RouteLocationNormalizedLoaded =
@@ -596,6 +597,11 @@ export function createNavigationApiRouter(options: RouterApiOptions): Router {
596
597
async function handleNavigate ( event : NavigateEvent ) {
597
598
if ( ! event . canIntercept ) return
598
599
600
+ if ( initialNavigation ) {
601
+ initialNavigation = false
602
+ return
603
+ }
604
+
599
605
event . intercept ( {
600
606
async handler ( ) {
601
607
const destination = new URL ( event . destination . url )
@@ -801,13 +807,32 @@ export function createNavigationApiRouter(options: RouterApiOptions): Router {
801
807
) {
802
808
// see above
803
809
started = true
804
- const initialLocation =
810
+ const initialLocation = resolve (
805
811
window . location . pathname +
806
- window . location . search +
807
- window . location . hash
808
- lastSuccessfulLocation = resolve (
809
- initialLocation
812
+ window . location . search +
813
+ window . location . hash
810
814
) as RouteLocationNormalized
815
+ pendingLocation = initialLocation
816
+ resolveNavigationGuards ( initialLocation , START_LOCATION_NORMALIZED )
817
+ . then ( ( ) => {
818
+ finalizeNavigation ( initialLocation , START_LOCATION_NORMALIZED )
819
+ } )
820
+ . catch ( err => {
821
+ const failure = err as NavigationFailure
822
+ if (
823
+ isNavigationFailure ( failure , ErrorTypes . NAVIGATION_GUARD_REDIRECT )
824
+ ) {
825
+ return navigate ( ( failure as NavigationRedirectError ) . to , {
826
+ replace : true ,
827
+ } )
828
+ } else {
829
+ return triggerError (
830
+ failure ,
831
+ initialLocation ,
832
+ START_LOCATION_NORMALIZED
833
+ )
834
+ }
835
+ } )
811
836
}
812
837
813
838
const reactiveRoute = { } as RouteLocationNormalizedLoaded
0 commit comments