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

Created on 1 Oct 2020  路  4Comments  路  Source: gatsbyjs/gatsby

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.

reacrouter and Links bug

Most helpful comment

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

All 4 comments

Happening the issue for me too.

Same for me.

same for me

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

benstr picture benstr  路  3Comments

Oppenheimer1 picture Oppenheimer1  路  3Comments

theduke picture theduke  路  3Comments

KyleAMathews picture KyleAMathews  路  3Comments

signalwerk picture signalwerk  路  3Comments