Skip to content

Commit be8a320

Browse files
committed
chore: fire initial navigation to load components
1 parent 34478a7 commit be8a320

File tree

1 file changed

+30
-5
lines changed
  • packages/router/src/navigation-api

1 file changed

+30
-5
lines changed

packages/router/src/navigation-api/index.ts

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export function createNavigationApiRouter(options: RouterApiOptions): Router {
7878
START_LOCATION_NORMALIZED
7979
)
8080

81+
let initialNavigation = true
8182
let isRevertingNavigation = false
8283
let pendingLocation: RouteLocation | undefined
8384
let lastSuccessfulLocation: RouteLocationNormalizedLoaded =
@@ -596,6 +597,11 @@ export function createNavigationApiRouter(options: RouterApiOptions): Router {
596597
async function handleNavigate(event: NavigateEvent) {
597598
if (!event.canIntercept) return
598599

600+
if (initialNavigation) {
601+
initialNavigation = false
602+
return
603+
}
604+
599605
event.intercept({
600606
async handler() {
601607
const destination = new URL(event.destination.url)
@@ -801,13 +807,32 @@ export function createNavigationApiRouter(options: RouterApiOptions): Router {
801807
) {
802808
// see above
803809
started = true
804-
const initialLocation =
810+
const initialLocation = resolve(
805811
window.location.pathname +
806-
window.location.search +
807-
window.location.hash
808-
lastSuccessfulLocation = resolve(
809-
initialLocation
812+
window.location.search +
813+
window.location.hash
810814
) 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+
})
811836
}
812837

813838
const reactiveRoute = {} as RouteLocationNormalizedLoaded

0 commit comments

Comments
 (0)