Handling dynamic routes with nuxt generate
papertokyo opened this issue · 7 comments
Firstly a huge thanks for making this module. It's exactly what I was looking for and was hoping I wouldn't have to create.
Is there a recommended way to handle localised, dynamic route generation?
Currently I'm getting route slugs as per the generate docs, then going over the locales and adding prefixes to all the routes. This feels hacky, and I suspect I'm doing it the 'wrong' way since the module already includes a routes config feature, but I couldn't see an obvious way to hook into this.
All the routes get generated properly, except the index page for non-default locales gets output with no filename. It ends up in the right place, but named '.html'. This is only when generate.subFolders is set to false.
Hi @papertokyo !
I didn't do much testing with the nuxt generate
command but I just tested it with the example project and it seems to work, even with generate.subFolders
set to false
.
What kind of dynamic routes do you have? Any way you could share your tests in a repo?
Thanks!
Hmm okay, I'll take a closer look and see if perhaps I'm doing something weird that would generate a blank path name. Netlify seems to be okay with the folders, so getting it working without subfolders is a 'nice to have', along with localising urls.
So just to clarify, the routes config object in nuxt-i18n is only for localising the slugs of folders in the pages tree, and when creating a routes array for generate, I should reference that config?
Yes I think so.
The routes option of generate lets you specify paths. It means that Nuxt will try to find a page that matches the route in order to generate the related HTML file.
This module only works with pages because it creates multiple localized routes from a single page.
Now, if you want to enable localization with generate.routes, how would you provide a different payload for each language? It would mean multiple locales x content?
I tried implementing generation of dynamic routes defined in generate.routes
with this module, but it's very difficult if not impossible because of the custom paths per language. Basically in the hook generate:extendRoutes
we would need to look up the original route matching a generated path, then look up the corresponding localization options and then generate localized paths.
If you don't need customized URLs per language, then maybe this alternative module works for you: https://github.com/njam/nuxt-i18n-module
The code that generates the dynamic routes is here: src/index.js
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Has any progress been made to this issue?
+1 to @CodyBontecou 's question