1

I am currently using UniversalRouter for routing in a react application that contains a form and other UI elements to allow users with admin permissions to make changes to data within the app for other users to see. I would like to be able to detect when a user is about to leave the page so that I can display a warning and give the user a choice to save their changes or abandon them.

I have seen other results that seem to address this problem for React-Router, but I have yet to find any results for achieving this using UniversalRouter.

In looking back at one of the blog posts where I discovered UniversalRouter, it seems like this would be something that I would need to implement by communicating with redux (i.e. by subscribing to state changes) rather than through the router directly.

I'll keep looking into this and self-answer if I get something working, but I would be very interested to know if anyone else has already implemented this 'warn the user about unsaved changes when they're about to leave the page' functionality in an app that uses UniversalRouter.

MoralCode
  • 1,954
  • 1
  • 20
  • 42
  • Slightly meta, but considering react-router has a tag, it might be nice to create a tag for [universalrouter questions](https://stackoverflow.com/search?q=UniversalRouter+React)? – MoralCode Sep 13 '20 at 20:43
  • From the [universal router chat](https://gitter.im/kriasoft/universal-router): https://github.com/ReactTraining/history/blob/master/docs/blocking-transitions.md – MoralCode Oct 11 '20 at 18:02

0 Answers0