diff --git a/packages/kit/src/runtime/app/navigation.js b/packages/kit/src/runtime/app/navigation.js index b8f2266bdac5..b406d4a6dd53 100644 --- a/packages/kit/src/runtime/app/navigation.js +++ b/packages/kit/src/runtime/app/navigation.js @@ -14,6 +14,7 @@ export const goto = import.meta.env.SSR ? guard('goto') : goto_; export const invalidate = import.meta.env.SSR ? guard('invalidate') : invalidate_; export const prefetch = import.meta.env.SSR ? guard('prefetch') : prefetch_; export const prefetchRoutes = import.meta.env.SSR ? guard('prefetchRoutes') : prefetchRoutes_; +export const routeParams = import.meta.env.SSR ? guard('routeParams') : routeParams_; /** * @type {import('$app/navigation').goto} @@ -49,3 +50,13 @@ async function prefetchRoutes_(pathnames) { await Promise.all(promises); } + +/** + * @returns {Record} + */ +function routeParams_() { + const { routes } = router.parse(new URL(location.href)); + if (routes.length === 0) return {}; + const match = routes[0][0].exec(location.pathname); + return routes[0][3](match); +}