Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling dynamic routes with nuxt generate #21

Closed
papertokyo opened this issue Feb 14, 2018 · 7 comments
Closed

Handling dynamic routes with nuxt generate #21

papertokyo opened this issue Feb 14, 2018 · 7 comments

Comments

@papertokyo
Copy link

papertokyo commented Feb 14, 2018

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.

This question is available on Nuxt.js community (#c19)
@paulgv
Copy link
Collaborator

paulgv commented Feb 17, 2018

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!

@papertokyo
Copy link
Author

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?

@lucpotage
Copy link

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?

@njam
Copy link

njam commented May 1, 2018

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

@stale
Copy link

stale bot commented Jun 13, 2019

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.

@stale stale bot added the wontfix label Jun 13, 2019
@stale stale bot closed this as completed Jun 20, 2019
@CodyBontecou
Copy link

Has any progress been made to this issue?

@dano5342
Copy link

+1 to @CodyBontecou 's question

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants