connectHistory()
ts
function connectHistory(router: Routes): void;
Connects a router instance to the history API. This allows us to reliably check for active routes, or to listen to path changes.
It is usually called once the routes are registered.
Parameters
router
Routes
Returns
void
Example
ts
class RootComponent extends LitElement {
readonly #router = new Router(this, [ ... ]);
constructor() {
super();
// bind history to router
connectHistory(this.#router);
}
override render() {
return html`
<main>${this.#router.outlet()}</main>
`;
}
// ...
}