lib
lib copied to clipboard
Loader for route with params
trafficstars
Not really an issue but more of a question.
You specify in the main README.md that a loader can use regex to specify a route :
// ...
{
locale: 'en',
key: 'home',
routes: ['/'], // you can use regexes as well!
loader: async () => (
await import('./en/home.json')
).default,
},
// ...
I'm guessing that's how you handle routes with params, I just wanted to know if you can confirm this or if there's a better way. I didn't find this in examples or in any of the READMEs.
Thanks for this library.
Hi @Alexandre-Fernandez! Thanks for your question.)
It does not need to be necessarily used together with url params, but can be. For example if you need to load specific translations according to url param, you could use something like:
{
locale: '<locale>',
key: '<key>',
routes: [/^\/some-page\?param=value$/],
loader: async () => (
await import('./<locale>/param_specific_translation.json')
).default,
}
Anyway, this is a good point – it should be included in some of examples so I'm adding it...