Skip to content

Commit 97e3796

Browse files
committed
chore: revert prevent default (not working)
chore: fix route paths logic
1 parent 58055b3 commit 97e3796

File tree

1 file changed

+22
-25
lines changed
  • packages/router/src/navigation-api

1 file changed

+22
-25
lines changed

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

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -592,16 +592,6 @@ export function createNavigationApiRouter(options: RouterApiOptions): Router {
592592
)
593593
}
594594

595-
async function handler(event: NavigateEvent) {
596-
const destination = new URL(event.destination.url)
597-
const pathWithSearchAndHash =
598-
destination.pathname + destination.search + destination.hash
599-
const to = resolve(pathWithSearchAndHash) as RouteLocationNormalized
600-
const from = currentRoute.value
601-
pendingLocation = to
602-
await resolveNavigationGuards(to, from)
603-
}
604-
605595
async function handleNavigate(event: NavigateEvent) {
606596
if (!event.canIntercept) return
607597

@@ -616,16 +606,10 @@ export function createNavigationApiRouter(options: RouterApiOptions): Router {
616606
delta > 0 ? NavigationDirection.forward : NavigationDirection.back,
617607
delta,
618608
}
619-
620-
try {
621-
await handler(event)
622-
} catch {
623-
event.preventDefault()
624-
}
625-
return
626-
}
627-
628-
if (event.navigationType === 'push' || event.navigationType === 'replace') {
609+
} else if (
610+
event.navigationType === 'push' ||
611+
event.navigationType === 'replace'
612+
) {
629613
navigationInfo = {
630614
type:
631615
event.navigationType === 'push'
@@ -637,7 +621,15 @@ export function createNavigationApiRouter(options: RouterApiOptions): Router {
637621
}
638622

639623
event.intercept({
640-
handler: () => handler(event),
624+
async handler() {
625+
const destination = new URL(event.destination.url)
626+
const pathWithSearchAndHash =
627+
destination.pathname + destination.search + destination.hash
628+
const to = resolve(pathWithSearchAndHash) as RouteLocationNormalized
629+
const from = currentRoute.value
630+
pendingLocation = to
631+
await resolveNavigationGuards(to, from)
632+
},
641633
})
642634
}
643635

@@ -648,9 +640,10 @@ export function createNavigationApiRouter(options: RouterApiOptions): Router {
648640
return
649641
}
650642

651-
const to = resolve(
652-
window.navigation.currentEntry!.url!
653-
) as RouteLocationNormalized
643+
const destination = new URL(window.navigation.currentEntry!.url!)
644+
const pathWithSearchAndHash =
645+
destination.pathname + destination.search + destination.hash
646+
const to = resolve(pathWithSearchAndHash) as RouteLocationNormalized
654647
const from = lastSuccessfulLocation
655648

656649
const fromIndex = event.from.index
@@ -800,7 +793,11 @@ export function createNavigationApiRouter(options: RouterApiOptions): Router {
800793
) {
801794
// see above
802795
started = true
803-
navigate(options.location).catch(err => {
796+
const initialLocation =
797+
window.location.pathname +
798+
window.location.search +
799+
window.location.hash
800+
navigate(initialLocation).catch(err => {
804801
if (__DEV__) warn('Unexpected error when starting the router:', err)
805802
})
806803
}

0 commit comments

Comments
 (0)