[gatsby-theme-i18n] Create language detection page "/" for prefixDefault=true #114
Unanswered
javiertury
asked this question in
Ideas
Replies: 1 comment
|
I would also really like to see a solution for this. Any news? |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
prefixDefault=trueprepends the locale to all URLs. This is nice feature but breaks the/page, trying to accesshttp://localhost:8000/returns a 404.The page
src/pages/index.tsxis working as intended, it's served at/<locale>. My objective is to create a language agnostic index page (/) that detects the browser locale and redirect the user tohttp://localhost:8000/<locale>/. However I'm not sure what is the right approach.I digged into the code of this theme and implemented a workaround. A page for language detection is added in
gatsby-node.jsand tricks gatsby-theme-i18n to ignore it.This is clearly not a good long term solution, and neither is to hardcode a
createRedirect.Could theme options be extended to specify a unprefixed index page?
EDIT: with gatsby 3 the workaround is not as effective. The client side router still loads the page, but there is no
public/index.htmlpage being generated and a 404 page is served instead which is visible for about 1-2 seconds.All reactions