Lime Web Components API Documentation - v6.25.0
    Preparing search index...

    Interface Navigator

    The Navigator service lets you navigate to a new location within the application, or update the current location with new data. A location is defined by a path and optional data.

    When navigating to a new location, a new entry will be pushed to the history stack in the browser and the EventDispatcher will emit a NavigationEvent.

    New locations can be registered using the RouteRegistry service

    // Listen on navigation events
    eventDispatcher.addListener('navigate', onNavigate);
    navigator.navigate('/object/deal/1001');

    function onNavigate(event: NavigationEvent) {
    console.log(event.detail);
    }
    interface Navigator {
        addBlocker(blocker: Blocker): void;
        createUrl(location: Partial<Location>): URL;
        getLocation(): Location;
        navigate(path: string, query?: Record<string, unknown>): void;
        navigate(location: LocationChange): void;
        removeBlocker(blocker: Blocker): void;
    }
    Index

    Methods

    • Add a blocker that can prevent navigation away from the current page, for example when there is some unsaved data that would otherwise be discarded.

      If the blocker function returns true navigation is blocked. If it returns false navigation will proceed as normal, if not blocked by other blockers.

      To later on resume navigation that was blocked, you can call the supplied Transition.retry method.

      Parameters

      • blocker: Blocker

        function to be called before navigation

      Returns void

      Blockers are not guaranteed to be executed upon a navigation event. Blockers will be executed until either all returns false or up until one of them returns true.

      navigator.addBlocker(myBlocker);

      function myBlocker(transition) {
      showConfirmDialog().then((shouldNavigate) => {
      if (shouldNavigate) {
      navigator.removeBlocker(myBlocker);
      transition.retry()
      }
      });
      return true;
      }
    • Create a URL for the given location

      Parameters

      • location: Partial<Location>

        the location to create a URL for. Any state of the location will be ignored.

      Returns URL

      the URL to the location

    • Navigate to a new location

      Parameters

      • path: string

        path to the location

      • Optionalquery: Record<string, unknown>

        query string parameters to append to the URL

      Returns void

      navigate - When the location has been changed the EventDispatcher will emit a NavigationEvent

    • Navigate to a new location or update the current location with new data

      By default, it is automatically decided whether to replace the current history entry or push a new one. If no new path is provided, or if it resolves to an unchanged path of the URL (not including the query string or fragment), the current history entry will be updated with the provided location data.

      You can also set location.method to push or replace instead. When pushing a new entry, location.state defaults to null. When replacing, state will only be changed if a new value is provided.

      Parameters

      • location: LocationChange

        a new location or parts of the location to replace

      Returns void

      navigate - When the location has been changed the EventDispatcher will emit a NavigationEvent

    • Removes a previously configured blocker.

      Parameters

      • blocker: Blocker

        previously added blocker function

      Returns void