Gatsby: Prevent navigation away from page

Created on 29 Dec 2018  路  3Comments  路  Source: gatsbyjs/gatsby

Summary

Is there an officially supported way I can prevent a user from navigating away from a page (ie, "this page contains a half-filled out form, are you sure you want to navigate away?") Ideally something like react-router's <Prompt> component, but obviously since Gatsby v2 uses reach router that won't work. I had a look at reach's docs and couldn't see any reference to it.

Thanks very much!

question or discussion

Most helpful comment

So is it impossible to block page reload in gatsby? Say i have a quiz app i don't what people to move away from the page until the finish or the time is up. How do i prevent navigating away from this page?

All 3 comments

See the third bullet point in tradeoffs https://reach.tech/router/credits

I assume this is within the site?

Ah thanks, I missed that. Yeah I primarily meant navigation within the site.

Reading that link, I think I'm convinced that just using session storage would cover my use-case fine, so I'll close this. Thanks for the help!

So is it impossible to block page reload in gatsby? Say i have a quiz app i don't what people to move away from the page until the finish or the time is up. How do i prevent navigating away from this page?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

magicly picture magicly  路  3Comments

benstr picture benstr  路  3Comments

totsteps picture totsteps  路  3Comments

ferMartz picture ferMartz  路  3Comments

brandonmp picture brandonmp  路  3Comments