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

gatsby-theme-i18n not redirecting to defaultLang when opening subpath without language prefix #124

Open
rlirli opened this issue May 13, 2021 · 5 comments

Comments

@rlirli
Copy link

rlirli commented May 13, 2021

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.

@gpessa
Copy link

gpessa commented Oct 27, 2021

mmm I feel we are never going to have a solution for this one.

@wollnyst
Copy link

Are there any updates on this issue or workarounds?

@ArtyMaury
Copy link

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);
  }
};

@cesarvarela
Copy link

More than a year has passed; any suggestions?

From the looks of it seems like using createRedirect is a good option?

@tonoli
Copy link

tonoli commented Oct 1, 2022

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

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

No branches or pull requests

6 participants