Can I have a prompt before navigating to another page

I have a editor page, I want to give user a prompt when user try to navigate away if the work is not saved .
I found something like this for react, I am wondering if readwood router can do something like this:
https://javascript.plainenglish.io/how-to-alert-a-user-before-leaving-a-page-in-react-a2858104ca94

Thanks!

That might be a react router v6 limitation unfortunately, you can see here: https://github.com/remix-run/react-router/issues/8139

Scratch that answer, I don’t know why I thought redwood used react router v6… It doesn’t, but I don’t see any possibility for prompt with the redwood router

Thanks

The standard way of handling this is the beforeunload event. Does that not work for you? There is nothing built-in to the redwood router for this

will before unload be fired when switch route?

Hey! I wanted to confirm that window.onbeforeunload doesn’t work. Is there any functionality like a useBlocker or react-router’s component?

No, I’m afraid not.

anyone figure out a way to handle this? window.onbeforeunload works for closing the tab, not for clicking around in the app

looks like useBlocker should be available in 8.0.0 feat(router): add router useBlocker hook by xmaxcooking · Pull Request #10873 · redwoodjs/redwood · GitHub

1 Like

Yup!