lit-ui-router / RoutedLitElement
Interface: RoutedLitElement<T>
Defined in: packages/lit-ui-router/src/interface.ts:334
A LitElement class constructor that can be used in state declarations.
The class should extend LitElement. The router delivers UIViewInjectedProps two ways: as a constructor argument on first render, and by assigning the uiViewProps property on every render (the only channel that fires when a sticky instance is reused). Constructor args are optional — argless constructors, as is typical for custom elements, work too. The sticky property can be set to true to reuse the same component instance across state transitions.
The same props are assigned to _uiViewProps, the property's name before 1.20, so a class that declares only that name keeps working.
The router owns both names on a routed class: it assigns them on every render, so a class cannot keep its own data there or define either as a getter without a setter.
Examples
Constructor injection
import { html, LitElement } from 'lit';
import type {
LitStateDeclaration,
UIRouterLit,
UIViewInjectedProps,
} from 'lit-ui-router';
declare const router: UIRouterLit;
class UserList extends LitElement {
uiViewProps: UIViewInjectedProps;
constructor(props: UIViewInjectedProps) {
super();
this.uiViewProps = props;
}
render() {
return html`<h1>Users</h1>`;
}
}
const usersState: LitStateDeclaration = {
name: 'users',
url: '/users',
component: UserList
};
router.stateRegistry.register(usersState);Argless constructor with property injection (typical Lit)
import { html, LitElement } from 'lit';
import { property } from 'lit/decorators.js';
import type { UIViewInjectedProps } from 'lit-ui-router';
class UserDetail extends LitElement {
// reactive property: sticky reuse re-renders when props are reassigned
@property({ attribute: false }) uiViewProps?: UIViewInjectedProps;
render() {
return html`<h1>${this.uiViewProps?.transition?.params().id}</h1>`;
}
}Extended by
Type Parameters
| Type Parameter | Default type |
|---|---|
T extends DefaultResolvesType | DefaultResolvesType |
Constructors
Constructor
new RoutedLitElement(props): LitElement & {
_uiViewProps?: UIViewInjectedProps<T>;
uiViewProps?: UIViewInjectedProps<T>;
};Defined in: packages/lit-ui-router/src/interface.ts:341
Construct signature. The router always passes props; classes may declare the parameter required, optional, or not at all.
Parameters
| Parameter | Type |
|---|---|
props | UIViewInjectedProps<T> |
Returns
LitElement & { _uiViewProps?: UIViewInjectedProps<T>; uiViewProps?: UIViewInjectedProps<T>; }
Properties
| Property | Type | Description | Defined in |
|---|---|---|---|
sticky? | boolean | If true, the same component instance is reused across state transitions | packages/lit-ui-router/src/interface.ts:353 |