Lightning Web Runtime :: Application Initialization
The lwr/init
module provides APIs which are responsible for:
This results in the root component(s) being renderable by the DOM on first page load.
Definition
interface InitAPI {
init(rootModules: [string, LightningElement][]): void;
}
Usage
import { init } from 'lwr/init';
import xAppRoot from 'x/appRoot';
import xNav from 'x/nav';
init([
['x/appRoot', xAppRoot],
['x/nav', xNav],
]);
Configuration
The default lwr/init
module used by an LWR route can be overridden with these steps:
- Create a module exporting an
init
function which implements the InitAPI
interface:
export function init(rootModules) {
rootModules.forEach(([moduleSpecifier, ctor]) => {
const elementName = toKebabCase(moduleSpecifier);
customElements.define(elementName, ctor.CustomElementConstructor);
});
}
- Configure the
init
module specifier in lwr.config.json:
{
"modules": [],
"routes": [
{
"id": "example",
"init": "example/init"
}
]
}