Current location before navigation
The Location before the navigation occurs.
Function to retry the blocked navigation
Call this function to resume navigation after it was blocked. Typically called after user confirmation or other async conditions are met.
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;
}
void confirmNavigation(transition);
// Block for now, `retry()` resumes the navigation if the user confirms
return true;
};
async function confirmNavigation(transition: Transition) {
const shouldNavigate = await showConfirmDialog();
if (!shouldNavigate) {
return;
}
hasUnsavedChanges = false;
navigator.removeBlocker(blocker);
transition.retry();
}
// Stands in for the dialog the component would open
async function showConfirmDialog(): Promise<boolean> {
return confirm('You have unsaved changes. Leave anyway?');
}
navigator.addBlocker(blocker);
Target location for navigation
The Location that will be navigated to if not blocked.
Navigation transition information
Describes a pending navigation from one location to another. Provided to Blocker functions to allow inspection of the navigation and optional retry after blocking.
Example: Inspect a pending navigation