tighten / ziggy

Use your Laravel routes in JavaScript.
MIT License
3.91k stars 248 forks source link

Trim slashes between origin and optional first param #637

Closed bakerkretzmar closed 1 year ago

bakerkretzmar commented 1 year ago

This PR ensures that there is only ever exactly one slash (/) between a generated URL's origin and path. This fixes an issue where it was possible to end up with a double slash if the very first segment of the path is an optional, omitted, route parameter. For example, {locale?}/foo could generate domain.com//foo if the locale param wasn't provided.

Note: This PR intentionally does not change the behaviour of omitted optional route params inside the route path. It's still possible to get double slashes there, e.g. with something like /foo/{param?}/bar, but this matches the behaviour of Laravel's route() function.

Resolves the issue discussed in #616. See https://github.com/tighten/ziggy/discussions/616#discussioncomment-5620680.