lwr-router-container

A router container provides navigation context by processing all navigation wires and events from its descendants in the DOM.

Properties 

PropertyTypeRequired/OptionalDescription
routerRouter objectOptionalObtained from the createRouter() API.
history-disabledBooleanOptionalSet history-disabled to true if your router container shouldn’t alter the browser’s History API during navigation events or location changes.

Syntax 

1<lwr-router-container
2  router="{router}"
3  <!-- Event handlers -->
4  onhandlenavigation="{handleNavigation}"
5  onprenavigate="{preNavigate}"
6  onpostnavigate="{postNavigate}"
7  onerrornavigate="{errorNavigate}"
8>
9  <my-nav></my-nav>
10  <lwr-outlet></lwr-outlet>
11</lwr-router-container>

Returns 

A router container fires these events:

  • onhandlenavigation

  • onprenavigate

    • Dispatched when a navigation event is received and a RouteDefinition match is found. event.preventDefault() cancels the navigation event. event.detail is a RouteChange object.

      1interface RouteChange {
      2  current?: DomRoutingMatch; // the current location info
      3  next: DomRoutingMatch; // location info for the incoming nav event
      4}
  • onpostnavigate

    • Dispatched when a navigation event has completed. event.detail is a DomRoutingMatch object for the current location.

      1interface DomRoutingMatch {
      2  url: string; // e.g. "/recipes/desserts/010?units=metric&yummy=yes"
      3  route: RouteInstance;
      4  routeDefinition: RouteDefinition;
      5}
  • onerrornavigate

    • Dispatched when there’s an error processing a navigation event. (For example, no RouteDefinition match or a prenavigate cancellation.) event.detail is a MessageObject.

      1interface MessageObject {
      2  code: string | number;
      3  message: string;
      4  level: number; // Fatal = 0, Error = 1, Warning = 2, Log = 3
      5}

See Also

Developer Preview Feature

Feature is available as a developer preview. Feature is not generally available unless or until Salesforce announces its general availability in documentation or in press releases or public statements. All commands, parameters, and other features are subject to change or deprecation at any time, with or without notice. Do not implement functionality developed with these commands or tools.

DID THIS ARTICLE SOLVE YOUR ISSUE?
Let us know so we can improve!