groutcho › Other frameworks › Lit
@diso.io/groutcho-lit
Reference
context
routerContext
const routerContext
Context for sharing a {@link RouterStore} down the DOM tree. Provide it from a
root element and consume it in <diso-outlet> / <diso-link> or your
own components.
controller
type ScrollBehavior =
| "top"
| "preserve"
| "restore"
| ((prev: MatchResult, current: MatchResult) => void);
RouterControllerOptions
interface RouterControllerOptions
|
|
manageTitle?: boolean |
Mirror store.title to document.title. Defaults to true. Turn off for SSR or when the host page owns the title. |
scrollBehavior?: ScrollBehavior |
How to reset scroll after each nav. Defaults to "top". A function lets you inspect (prev, current) and scroll however you want. |
RouterController
class RouterController implements ReactiveController
Lit ReactiveController that binds a host element to a groutcho router store.
Pass an existing {@link RouterStore} (e.g. shared via context) or a config to
create one. The host re-renders whenever the current match changes.
class MyApp extends LitElement {
router = new RouterController(this, { routes, redirects });
render() {
const { match } = this.router;
return html`<h1>${match.route?.name}</h1>`;
}
}
|
|
readonly store: RouterStore |
|
constructor(host: ReactiveControllerHost, source: RouterStore | RouterStoreConfig, options: RouterControllerOptions = {}) |
|
get match(): MatchResult |
The current match snapshot. |
get title(): string |
Current title (mirrors store.title). |
go = (input: Input): MatchResult |
Navigate. Bound so it can be passed as a handler. |
get(name: string): Route |
Look up a route by name (shorthand for store.get). |
setTitle(title: string): void |
Imperative title setter (mirrors store.setTitle). |
onGo(listener: GoListener): () => void |
Subscribe to nav events. Returns an unsubscribe. |
onTitle(listener: TitleListener): () => void |
Subscribe to title changes. Returns an unsubscribe. |
onError(listener: ErrorListener): () => void |
Subscribe to error changes. Returns an unsubscribe. |
hostConnected(): void |
|
hostDisconnected(): void |
|
elements
RenderPage
type RenderPage = (match: MatchResult) => unknown;
How an outlet turns a match into renderable content.
LayoutFn
type LayoutFn = (match: MatchResult, children: unknown) => unknown;
Layout function shape. Receives the current match and the inner content
(already-rendered page or nested layout). Layouts compose outermost-first.
DisoOutlet
class DisoOutlet extends RouterElement
|
|
@property({ attribute: false }) renderPage?: RenderPage |
Optional custom renderer; overrides the default page handling. |
override render(): unknown |
|
DisoLink
class DisoLink extends RouterElement
|
|
@property() to = "" |
A url or route name to navigate to. |
@property({ attribute: false }) params?: Params |
Params used with a route-name to (and to build the href). |
@property({ attribute: false }) input?: Input |
A full input object; takes precedence over to/params. |
protected get target(): Input |
|
protected href(): string |
|
protected onClick = (event: MouseEvent): void |
|
override render(): TemplateResult |
|
DisoNavLink
class DisoNavLink extends DisoLink
|
|
@property({ attribute: "active-class" }) activeClass = "active" |
Class name added to the <a> when active. Defaults to "active". |
@property({ attribute: "active-exact", type: Boolean }) activeExact = false |
Match strictly against the current pathname / route-name (no prefix). |
override render(): TemplateResult |
|
From @diso.io/groutcho-core
Exported as they are in @diso.io/groutcho-core: Component, createBrowserHistory, createMemoryHistory, createRouter, ErrorListener, GoListener, History, Input, InputObject, MatchResult, Params, RedirectResult, RedirectTest, Route, RouteConfig, RouteError, RouteInput, Router, RouterConfig, RouteRedirect, RouterStore, RouterStoreConfig, StoreListener, TitleListener, TitleValue.