Prevent navigation when data is dirty (React, Flow Router)

I’d like to show a confirmation modal dialog if the user tries to navigate away from a page with dirty data. My React component has an isDirty flag on it’s state, so it seems like I probably need to handle that flag in some way with Flow Router? Does anybody know how to do that (or have another approach)?

I’d also like to warn if the user hits the refresh button in the browser or performs any other browser navigation that bypasses the routing - is that possible?