Prefix to route names #472
-
DescriptionIs there any way to add a default prefix to a route name in Ziggy? SuggestionEvery time I'm using the route() or route().current(), I have to use it like this route(locale+".users.show). I wanted to add a prefix so this locale is automatically added every time. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
@CosmicodeStudio if I were you I would wrap the // assuming `locale` is available globally
const locale = 'pt';
const localeRoute = (name, params, absolute, config) => {
return route(`${locale}.${name}`, params, absolute, config);
}
localeRoute('users.show'); // will return the result of `route('pt.users.show')` For Let me know if that works! |
Beta Was this translation helpful? Give feedback.
@CosmicodeStudio if I were you I would wrap the
route()
function in your own helper to pass the locale in when you call it, something like this:For
current()
you can probably use wildcards,route().current('*.users.show')
should work. If you don't want to do that you could create another wrapper similar to the one above but forroute().current()
.Let me know if that works!