Information about the pending navigation
true to block navigation, false to allow it
import {
Blocker,
PlatformServiceName,
Transition,
} from '@limetech/lime-web-components';
const navigator = platform.get(PlatformServiceName.Navigator);
let hasUnsavedChanges = false;
const blocker: Blocker = (transition: Transition) => {
if (!hasUnsavedChanges) {
return false;
}
if (confirm('You have unsaved changes. Leave anyway?')) {
hasUnsavedChanges = false;
navigator.removeBlocker(blocker);
transition.retry();
}
return true;
};
navigator.addBlocker(blocker);
// Remember to remove the blocker in `disconnectedCallback()`
navigator.removeBlocker(blocker);
Function to determine if navigation should be blocked
A blocker is registered with Navigator.addBlocker to prevent navigation under certain conditions (e.g., unsaved changes).
Return
trueto block navigation, orfalseto allow it. If blocked, use Transition.retry to resume navigation later.