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

Example

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

function onNavigate(event: NavigationEvent) {
console.log(event.detail);
}

Hierarchy

  • Navigator

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.

    Note

    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.

    Example

    navigator.addBlocker(myBlocker);

    function myBlocker(transition) {
    showConfirmDialog().then((shouldNavigate) => {
    if (shouldNavigate) {
    navigator.removeBlocker(myBlocker);
    transition.retry()
    }
    });
    return true;
    }

    Parameters

    • blocker: Blocker

      function to be called before navigation

    Returns void

  • Create a URL for the given location

    Returns

    the URL to the location

    Parameters

    • location: Partial<Location>

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

    Returns URL

  • Navigate to a new location

    Emits

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

    Parameters

    • path: string

      path to the location

    • Optional query: Record<string, unknown>

      query string parameters to append to the URL

    Returns void

  • 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.

    Emits

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

    Parameters

    • location: LocationChange

      a new location or parts of the location to replace

    Returns void

  • Removes a previously configured blocker.

    Parameters

    • blocker: Blocker

      previously added blocker function

    Returns void