Repository navigation
feat: add resolvePath export - #9949
Conversation
…o a relative path
🦋 Changeset detectedLatest commit: 110d716 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
| * @param {Record<string, string>} params | ||
| * @returns {string} | ||
| */ | ||
| export function resolvePath(id, params) { |
There was a problem hiding this comment.
Since we call it route id in other places I think it would make sense to reuse that nomenclature here
| export function resolvePath(id, params) { | |
| export function resolveRoute(id, params) { |
Alternatively even resolveRouteId.
Thoughts?
There was a problem hiding this comment.
I think resolvePath is correct — we're resolving a path from a route ID + some parameters.
That said, resolvePath sounds like path.resolve, i.e. you might expect to see resolvePath(base, relative). I don't know if there's a good name for this that doesn't sound clunky and un-SvelteKit-like.
There was a problem hiding this comment.
Yeah, that was my reasoning as well, Rich -- I think the current name is a good mix of what it does and brevity, and the example is pretty darn clear
| * @returns {string} | ||
| */ | ||
| export function resolvePath(id, params) { | ||
| return resolve_entry(id, params); |
There was a problem hiding this comment.
rather than calling the function indirectly like this, we should either a) re-export it or b) put the implementation here, and use that internally instead of resolve_entry (probably better, though a more significant change)
There was a problem hiding this comment.
Agreed, let's put the implementation here. Makes it more clear that changing the implementation affects the public API.
Co-authored-by: Rich Harris <richard.a.harris@gmail.com>
Rich-Harris
left a comment
There was a problem hiding this comment.
ugh i just realised that this doesn't show up in the docs, because we also need to update ambient.d.ts
this fuels my desire to build the missing library for generating .d.ts bundles with declare module from source #9895 (comment)
|
ah i tell a lie, it's not |
|
Why is the second argument optional? |
|
The second argument isn't optional, but the values of that record are because because optional route params are optional, so if you wanted to |
|
ohhh i read it as |
|
Woohoo! That was fast. |
Closes #9934.
Adds a
resolvePathexport for building relative paths from route IDs and params:Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm testand lint the project withpnpm lintandpnpm checkChangesets
pnpm changesetand following the prompts. Changesets that add features should beminorand those that fix bugs should bepatch. Please prefix changeset messages withfeat:,fix:, orchore:.