Lime Web Components API Documentation - v7.4.0
    Preparing search index...

    Type Alias Blocker

    Blocker: (transition: Transition) => boolean

    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 true to block navigation, or false to allow it. If blocked, use Transition.retry to resume navigation later.

    Type Declaration

      • (transition: Transition): boolean
      • Parameters

        • transition: Transition

          Information about the pending navigation

        Returns boolean

        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);