roxiness / routify

Automated Svelte routes
https://routify.dev
1.87k stars 87 forks source link

fix: url helper not honoring params passed in #503

Closed fdm1 closed 1 year ago

fdm1 commented 1 year ago

If calling $url("/some/path/:user_id", {user_id: 123}), but your current path was "/foo/bar?u=789", because the populateUrl function uses the inheritedParams first, the result of that $url call would be /some/path/789ser_id, because it would replace only the :u part from the state params, instead of using the full :user_id from the passed params.

jakobrosenberg commented 1 year ago

Thanks for the PR @fdm1 . I think the user params should always take precedence over the inherited params.

The issue seems to come from this line https://github.com/roxiness/routify/blob/aff213471b025561f95f19f16e76ab2d52b9b863/runtime/utils/index.js#L152

Something like this might solve it

const re = new RegExp(`:${key}(\/|$)`)
path = path.replace(`:${key}`, value)
fdm1 commented 1 year ago

👍 @jakobrosenberg that seems to work fine, other than it flips out putting a const or let in the for loop. Either way, pushing that up.

jakobrosenberg commented 1 year ago

Look good. Could I get you to reverse the inheritedParams and params on L148?

fdm1 commented 1 year ago

Could I get you to reverse the inheritedParams and params

Done and done

jakobrosenberg commented 1 year ago

Much appreciated. 🙏 The fix should be available in a couple of minutes.

github-actions[bot] commented 1 year ago

:tada: This PR is included in version 2.18.10 :tada:

The release is available on:

Your semantic-release bot :package::rocket: