Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/kit/src/runtime/app/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -49,3 +50,13 @@ async function prefetchRoutes_(pathnames) {

await Promise.all(promises);
}

/**
* @returns {Record<string, string>}
*/
function routeParams_() {
const { routes } = router.parse(new URL(location.href));
if (routes.length === 0) return {};
const match = routes[0][0].exec(location.pathname);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could use a comment as to why this line and the next are routes[0]. It seems like it's only checking the first route? Why is that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a really good comment. I think if there's multiple ambiguous matching routes it gives them all, we'd probably want the first or the last, I'll need to investigate. The order comes from whatever order they're in generated/manifest.js.

Also I don't love the magic indices after that. I should cast it as a CSRPage type and destructure it instead.

I'll have an update soon.

return routes[0][3](match);
}