Gatsby: Get previous path/route in 404 page

Created on 9 Aug 2019  路  3Comments  路  Source: gatsbyjs/gatsby

Summary

Is there anyway for me to retrieve the previous page that the user was when they navigate to route that doesn't exist and hit my 404 page. I basically want my 404 page to dynamically change depending on how the user gets there. I currently have this in my gatsby-browser.js

exports.onRouteUpdate = ({location, prevLocation}) => {
    if(location !== null && prevLocation !== null){
        location.state.prevPath = prevLocation.pathname
    }
    console.log(location)
}

but the location variable seems to reset and the prevLocation is null when I navigate from a normal page to a 404 page.

Relevant information

Environment (if relevant)

File contents (if changed)

gatsby-config.js: N/A
package.json: N/A
gatsby-node.js: N/A
gatsby-browser.js:

// Code Highlighting
require('./src/styles/code.scss')


exports.onRouteUpdate = ({location, prevLocation}) => {
    if(location !== null && prevLocation !== null){
        location.state.prevPath = prevLocation.pathname
    }
    console.log(location)
}

gatsby-ssr.js: N/A

stale?

Most helpful comment

I'd still like a response on this if possible.

All 3 comments

Hiya!

This issue has gone quiet. Spooky quiet. 馃懟

We get a lot of issues, so we currently close issues after 30 days of inactivity. It鈥檚 been at least 20 days since the last update here.

If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not stale" to keep this issue open!

As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing!

Thanks for being a part of the Gatsby community! 馃挭馃挏

I'd still like a response on this if possible.

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.

As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing!

Thanks again for being part of the Gatsby community!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hobochild picture hobochild  路  3Comments

3CordGuy picture 3CordGuy  路  3Comments

ferMartz picture ferMartz  路  3Comments

rossPatton picture rossPatton  路  3Comments

timbrandin picture timbrandin  路  3Comments