gatsby-theme-i18n not redirecting to defaultLang when opening subpath without language prefix
rlirli opened this issue · comments
Describe the bug:
I am using the following configuration file for a gatsby.js page. With the defaultLang set to en
, it correctly redirects the user from domain.com
to the localized version domain.com/en
. However, this redirect does not work with subpaths. Opening domain.com/about
leads to 404.
// gatsby-config.js
{
resolve: `gatsby-theme-i18n`,
options: {
defaultLang: `en`,
prefixDefault: true,
configPath: require.resolve(`./i18n/config.json`),
locales: `en de`,
},
}
Expected behavior:
A user who accesses domain.com/about
should by default redirect to domain.com/en/about
.
Is there any way to do this with gatsby-theme-i18n directly or other workarounds? Thanks in advance!
I understand this might be by design. Alternatively, I could disable prefixDefault. Then domain.com/about
would work, but domain.com/en/bout
would lead to 404.
mmm I feel we are never going to have a solution for this one.
Are there any updates on this issue or workarounds?
I've got a workaround, it's ugly but it works. I duplicated the pages of the default language.
The problem is that if you create a page from scratch that redirects you to the default language (or the user default) the SEO is bad. because of the redirection.
In gatsby-node.js :
exports.onCreatePage = ({ page, actions }) => {
const { createPage } = actions;
if (page.path.startsWith("/fr/")) {
const newPage = { ...page, path: page.path.substring(3) };
createPage(newPage);
}
};
More than a year has passed; any suggestions?
From the looks of it seems like using createRedirect
is a good option?
defaultLang
I just cloned the project (https://github.com/gatsbyjs/themes/starters/example-react-intl
) and it doesn't redirect the user from domain.com
to the localized version domain.com/en
I have a 404 not found on localhost:8000
. It should redirect to the local homepage localhost:8000/en