LwrConfigRouteDefinition

To configure a router module with the Router Module Provider, you have to set up both LwrRouterConfig and LwrConfigRouteDefinition.

Important

Syntax 

1interface LwrConfigRouteDefinition<TMetadata = Record<string, any>> {
2    id: string;
3    uri: string;
4    page: Partial<PageReference>
5    patterns?: { [paramName: string]: string };
6    exact?: boolean;
7    metadata?: TMetadata;
8    // LwrConfigRouteDefinition must have ONE of the following, not both
9    handler?: string; // a STRING reference to the handler class
10    component?: string; // a STRING reference to a page component
11}

Properties 

LwrConfigRouteDefinition object contains similar properties as the RouteDefinition object. handler and component are string references, as LwrConfigRouteDefinition is pure JSON and can’t contain any functions. Only define either the handler or component property, not both.

PropertyTypeRequired/OptionalDescription
idStringOptionalEach LwrConfigRouteDefinition must have a unique id identifier.
uriStringOptionalA pattern for URI locations that match the LwrConfigRouteDefinition. You can’t use the # and * characters.
pageRequiredThe form of page references that match the LwrConfigRouteDefinition. page values can be :parameter bindings, which map a path or query parameter from the URI to an attributes or state property, or literal bindings, which hard code a type, attribute, or state property to a literal value. Literal bindings can’t contain the following characters: ?, *, #, &, +, ;, (, ).
patternsOptionalA regular expression that a parameter has to match to be valid. To prevent unexpected values in the expression pattern, explicitly wrap the expression in the start-of-line character (^) and end-of-line character ($). For example: {"patterns": {"parameter": "^id[0-9a-zA-Z]{5}$"}}.
exactBooleanOptionalIf there’s a nested router, this value must be false. The default value is true.
metadataOptionalDeveloper-defined metadata in the form of key (string) and value (any type) pairs. You can use the metadata property to attach additional information to an LwrConfigRouteDefinition. Extend LwrConfigRouteDefinition for required or more strongly typed metadata.
handlerStringSee descriptionAn LwrConfigRouteDefinition must contain a handler or a component, but not both. handler is a string reference to the RouteHandler class specifier.
componentStringSee descriptionAn LwrConfigRouteDefinition must contain a handler or a component, but not both. component is a string reference to the view component specifier. Use this property to directly specify the view component without authoring a route handler.

Example 

Two LwrConfigRouteDefinition objects
1{
2    "id": "home",
3    "uri": "/",
4    "component": "examples/home",
5    "page": {
6        "type": "home"
7    },
8    "metadata": {
9        "title": "Home"
10    }
11},
12{
13    "id": "namedPage",
14    "uri": "/:pageName",
15    "handler": "examples/namedPageHandler",
16    "page": {
17        "type": "namedPage",
18        "attributes": {
19            "pageName": ":pageName"
20        }
21    }
22}

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!