next-translate
next-translate copied to clipboard
How to setup for multiple dynamic paths?
So, I have this dynamic path in my project /blog/{slug}
. By default any {locale}/blog/{slug}
site would result in a 404 error.
Right now, my getStaticPaths
function looks something like:
export const getStaticPaths: GetStaticPaths = async () => {
const blogSlugs = [
...functionToGetAllBlogPostsSlugs(),
'my-blog',
'second-blog',
'random-blog',
]
const paths = blogSlugs.map((slug: string) => `/blog/${slug}`);
return {
paths,
fallback: false,
};
};
how can I update it so it generates paths for all the available locales?
Hello, I've just opened an issue with some code in it, that I think you would find useful :) #546
@pimvh would you mind elaborating on your issue and what you did to fix it?
The issue for me is: I don't have a blog in English and the other locale. Also, I don't want to. I want it to be just in English. But, I want the links there to go to the right locale.
Basically, with my config, blogs are accessed just fine, but since they are part of the English site, any link will make it go to the English site, even when the locale is different, let's say Spanish.
Hi @jahirfiquitiva,
I think the issue you are having is different from mine, as you want to stick just to one language. Have you looked at i18 supported rewrites?
Added more locales, and redirecting them to English might solve your issue if I am not mistaken.
However, you can view the code I wrote, it's on my Github. Without going into too much detail, after changing to fallback : true, I did some fallback magic on the blog page, and built in a fail-safe for pages not loading in the function that gets my Postdata. If a user now types an url that does not exist, it attempts to load it, fails, and neatly displays an error. Good enough for my taste. 👍
Feel free to have a look at the code and shoot me a message, if you need any help.