question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Doesn't work together with client routes and reach router

See original GitHub issue

I’m using client routes in Gatsby together with gatsby-plugin-react-i18next. When I’m trying to access one of the client routes while not using the default language, e.g. the url is prefixed with /sv, then I get that the route doesn’t exists. If I add the prefix /sv to the router basepath, the Default component/path is working but not the Profile component/path.

While using the default language without the /sv prefix, everything is working as expected.

src/pages/account.tsx

<Router basepath={'/account'}>
  <AccountRoute path="/profile" component={Profile} />
  <Default path="/" />
</Router>

gatsby-node.js

exports.onCreatePage = async ({ page, actions }) => {
  const { createPage } = actions
  if (page.path.match(/^\/account/)) {
    page.matchPath = "/account/*"

    createPage(page)
  }
}

I’ve also tried to add the prefix /sv to the matchPath in gatsby-node.js but then I’m redirected to double prefixes /sv/sv route that doesn’t exists. If I tell gatsby-plugin-react-i18next to not generate language pages for the account pages, I get the same result.

gatsby-config.js

{
  resolve: `gatsby-plugin-react-i18next`,
  options: {
    ...
  },
  pages: [
    {
      matchPath: '/:lang?/account/(.*)',
      getLanguageFromPath: true
    },
  ]
}

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:2
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

0reactions
nithyananthan-s02commented, Mar 6, 2022

Am facing the same issue. I tried the approaches specified above however, unfortunately, it is not working. Am getting route NOT FOUND error. Any updates on this ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Overview - Reach Router
Reach Router has a small footprint, supports only simple route patterns by design, and has strong (but experimental) accessibility features. Future. Reach ...
Read more >
Gatsby <Link> or @reach-router <Link> between static page ...
I use gatsby link if the page destination is using the default gatsby routing configuration. I don't know if I'm missing out on...
Read more >
Migrating to React Router v6: A complete guide
Migrate your React Router applications from v5 to v6 with this in-depth guide, including a review of additions and improvements from v5.
Read more >
Default gateway route doesn't appear in Routing Table
Use the Route Add command to manually add the default route for the network interface that you added. Click Start, click Run, type...
Read more >
Client-only Routes & User Authentication - Gatsby
Client -only routes will exist on the client only and will not correspond to ... learn more about how routing works from the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found