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

fix: add language prefix for dynamic routes #71

Merged
merged 1 commit into from
Aug 6, 2022

Conversation

krotovic
Copy link
Contributor

This PR should fix the #57 issue.

Gatsby uses page.matchPath for client-side routes and this plugin never changes that to add language prefix.

Reference: https://www.gatsbyjs.com/docs/gatsby-internals-terminology/#matchpath

@MarcoG3
Copy link

MarcoG3 commented Jun 4, 2021

Quick workaround I'm using based on your contribution which is useful to avoid installing this PR as a dependency.

In gatsby-node.js

exports.onCreatePage = ({ page, actions }) => {
  const { createPage, deletePage } = actions;

  if (page.matchPath === '/your-path/:id') {
    deletePage(page);

    createPage({
      ...page,
      matchPath: page.context.language !== page.context.i18n.defaultLanguage ? `${page.context.language}/your-path/:id` : page.matchPath,
    });
  }
};

@krotovic
Copy link
Contributor Author

@jimmyn Still no progress on this PR?

@jimmyn jimmyn merged commit 77256bd into microapps:master Aug 6, 2022
@jamesdamild
Copy link

hi @jimmyn , i am working with this gatsby project, when I create client routes with the createPage.
the English version works fine which is the default, but when i change to the french, the url changes to :http://localhost:8000/fr/fr/checkout/, it's adding double fr on the path. any help why it's doing that ?

here is my createPage on the gatsbynode:

if (page.path.startsWith(`/checkout`)) {
    page.matchPath = `/checkout/*`
    createPage(page)
  }

here is the router for it on the checkout page under the page folder:
<Router> <AuthenticatedRoute path='/checkout/:cartId' component={Home} /> <AuthenticatedRoute path='/checkout/:cartId/payment' component={Payment} /> <NotFound default /> </Router>

help please any idea why it does that ?

thanks

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

Successfully merging this pull request may close these issues.

4 participants