Skip to content

Commit 9772a2e

Browse files
committed
chore: add initial bootstrap
1 parent 2d21d50 commit 9772a2e

File tree

1 file changed

+28
-1
lines changed
  • packages/router/src/navigation-api

1 file changed

+28
-1
lines changed

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

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,33 @@ export function createNavigationApiRouter(options: RouterApiOptions): Router {
716716
)
717717
}
718718

719+
async function start(location: RouteLocationRaw) {
720+
const to = resolve(location) as RouteLocationNormalized
721+
const from = START_LOCATION_NORMALIZED
722+
723+
pendingLocation = to
724+
725+
try {
726+
await resolveNavigationGuards(to, from)
727+
finalizeNavigation(to, from)
728+
} catch (error) {
729+
const failure = error as NavigationFailure
730+
// at start, a guard failure cannot be reverted, we just notify.
731+
finalizeNavigation(to, from, failure)
732+
if (isNavigationFailure(failure, ErrorTypes.NAVIGATION_GUARD_REDIRECT)) {
733+
// if there is a redirect, we navigate to it replacing the current entry.
734+
await navigate((failure as NavigationRedirectError).to, {
735+
replace: true,
736+
})
737+
} else {
738+
// for other errors we just notify, the user is left in the blank page.
739+
triggerError(failure, to, from)
740+
}
741+
} finally {
742+
pendingLocation = null
743+
}
744+
}
745+
719746
const history: RouterHistory = {
720747
base: options.base || '/',
721748
location: options.location,
@@ -784,7 +811,7 @@ export function createNavigationApiRouter(options: RouterApiOptions): Router {
784811
window.location.pathname +
785812
window.location.search +
786813
window.location.hash
787-
navigate(initialLocation).catch(err => {
814+
start(initialLocation).catch(err => {
788815
if (__DEV__) warn('Unexpected error when starting the router:', err)
789816
})
790817
}

0 commit comments

Comments
 (0)