Gatsby: Gatsby Link go back

Created on 18 Jun 2018  路  6Comments  路  Source: gatsbyjs/gatsby

I am trying to add a back button with the Gatsby Link - is there a way to do this?

stale? question or discussion

Most helpful comment

@b0gd4n, I think the reason that you're having trouble creating a back button is because @reach/router does not include this, the way that react-router used to.

That feature has not yet been implemented in @reach/router, but an issue is open for it: https://github.com/reach/router/issues/44

One proposed suggestion is to just use the history API on the window, like this:

window.history.back()

or

window.history.go(-1)

Keep in mind that will not work if you are doing server-side rendering, since on the server-side, window is not defined.

All 6 comments

Hi @b0gd4n, I think this might help you.
Using Links from gatsby, you can try this :

import React from 'react';
import Link from 'gatsby-link';

export default () => {
  return (
    <div>
      <Link to="/about">
                <ButtonPrimary>About</ButtonPrimary>
              </Link>
   </div>
 )
}

Consider this is happen on the pages/indes.js .

@b0gd4n, I think the reason that you're having trouble creating a back button is because @reach/router does not include this, the way that react-router used to.

That feature has not yet been implemented in @reach/router, but an issue is open for it: https://github.com/reach/router/issues/44

One proposed suggestion is to just use the history API on the window, like this:

window.history.back()

or

window.history.go(-1)

Keep in mind that will not work if you are doing server-side rendering, since on the server-side, window is not defined.

Old issues will be closed after 30 days of inactivity. This issue has been quiet for 20 days and is being marked as stale. Reply here or add the label "not stale" to keep this issue open!

Hey again!

It鈥檚 been 30 days since anything happened on this issue, so our friendly neighborhood robot (that鈥檚 me!) is going to close it.

Please keep in mind that I鈥檓 only a robot, so if I鈥檝e closed this issue in error, I鈥檓 HUMAN_EMOTION_SORRY. Please feel free to reopen this issue or create a new one if you need anything else.

Thanks again for being part of the Gatsby community!

reach/router#44 has been implemented in reach router 1.2

This should be re-opened.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

3CordGuy picture 3CordGuy  路  3Comments

ferMartz picture ferMartz  路  3Comments

magicly picture magicly  路  3Comments

brandonmp picture brandonmp  路  3Comments

hobochild picture hobochild  路  3Comments