Hi. I have a use case where I’d like to prompt the user to confirm/cancel navigation, because they will lose the data they’ve typed into a form if they leave the page without saving.
I can see there’s a small example in the Lit docs, but has anyone tried it with React?
Here’s the Lit example:
my-view.ts
import { LitElement } from ‘lit’;
import { customElement } from ‘lit/decorators.js’;
import {
BeforeEnterObserver,
PreventAndRedirectCommands,
Router,
RouterLocation
} from ‘@vaadin/router’;
@customElement(‘my-view’)
class MyView extends LitElement implements BeforeEnterObserver {
onBeforeEnter(
location: RouterLocation,
commands: PreventAndRedirectCommands,
router: Router) {
if (location.pathname === ‘/cancel’) {
return commands.prevent();
}
}
}