diff --git a/src/client/app/router.ts b/src/client/app/router.ts index f8783994..c637fed7 100644 --- a/src/client/app/router.ts +++ b/src/client/app/router.ts @@ -7,6 +7,8 @@ import { getScrollOffset, inBrowser, withBase } from './utils' export interface Route { path: string + hash?: string + query?: string data: PageData component: Component | null } @@ -45,10 +47,6 @@ export interface Router { * Called after the route changes. */ onAfterRouteChange?: (to: string) => Awaitable - /** - * @deprecated use `onAfterRouteChange` instead - */ - onAfterRouteChanged?: (to: string) => Awaitable } export const RouterSymbol: InjectionKey = Symbol() @@ -80,7 +78,8 @@ export function createRouter( href = normalizeHref(href) if ((await router.onBeforeRouteChange?.(href)) === false) return if (!inBrowser || (await changeRoute(href, options))) await loadPage(href) - await (router.onAfterRouteChange ?? router.onAfterRouteChanged)?.(href) + syncRouteQueryAndHash() + await router.onAfterRouteChange?.(href) } } @@ -165,6 +164,11 @@ export function createRouter( } } + function syncRouteQueryAndHash() { + route.query = location.search + route.hash = location.hash + } + if (inBrowser) { if (history.state === null) history.replaceState({}, '') window.addEventListener( @@ -216,11 +220,13 @@ export function createRouter( if (e.state === null) return const href = normalizeHref(location.href) await loadPage(href, (e.state && e.state.scrollPosition) || 0) - await (router.onAfterRouteChange ?? router.onAfterRouteChanged)?.(href) + syncRouteQueryAndHash() + await router.onAfterRouteChange?.(href) }) window.addEventListener('hashchange', (e) => { e.preventDefault() + syncRouteQueryAndHash() }) }