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.

Using Link from @reach/router is broken in Dev-Mode since 2.24.65

See original GitHub issue

Description

Up to Gatsby 2.24.64 is was possible to use Link from @reach/router to link between pages. Starting from 2.24.65 you get 404-errors. We need to use Link from @reach/router in our project because we have to rebundle our components without a Gatsby dependency. With Link from “gatsby” it works fine.

I suspect that this issue is related to this fix, but I’m not totally sure:

https://github.com/gatsbyjs/gatsby/pull/27003

Steps to reproduce

Create a new starter project:

gatsby new gatsby-test https://github.com/gatsbyjs/gatsby-starter-hello-world

As src/pages/index.js use:

import { Link } from "@reach/router"
import React from "react"

export default function Home() {
  return <Link to="/page2">Page2</Link>
}

As src/pages/page2.js use:

import { Link } from "@reach/router"
import React from "react"

export default function Page2() {
  return <Link to="/">Home</Link>
}

Expected result

Now run it in develop mode. Clicking on the link works fine with Gatsby version up to 2.24.64, but results in the error page with 2.24.65 and above.

Actual result

With Gatsby 2.24.65 and above you’ll get 404-error page.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:16
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
sarahannnicholsoncommented, Jan 15, 2021

As a workaround in development my process has been:

  1. Click on a link that goes to the page I want
  2. Get the 404 page
  3. Refresh the page and then I get my page appearing. Which just reinforces that this is an issue with the linking.

Alternatively, going straight to the route you want works for me as well.

Can confirm this only happens on development, gatsby build is fine. Gatsby v2.30.2

3reactions
tracy-liucuicommented, Dec 8, 2020

We had the same issue, solved it by using gatsby link.

Gatsby link handles some gatsby-specified logic, if you want to make the reach-router link work the same, you should handle them by yourself. Mainly the hover event I guess https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-link/src/index.js#L223

Read more comments on GitHub >

github_iconTop Results From Across the Web

Routing not working as expected in React app using react ...
It seems modifying my webpack config for dev worked. devServer: { port: 4000, hot: true, //enable webpack hot module replacement open: true, ...
Read more >
Fixing the 'cannot GET /URL' error on refresh with React ...
In this post you'll learn how to fix the 'cannot GET /URL' error with React Router. Along the way, you'll also learn how...
Read more >
Link v6.6.1 - React Router
In react-router-dom , a <Link> renders an accessible <a> element with a real href that points to the resource it's linking to. This...
Read more >
React router page links not working in production : r/reactjs
So I have a react site where I use react router to link to different pages. It works locally, but when I run...
Read more >
Getting started with React Router v4 - Pusher Blog
Next, create a new app, change into the app's directory and start the app in development mode. create-react-app portfolio cd portfolio npm start....
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