groutcho @diso.io/groutcho
Reference
elements
RenderPage |
How an outlet turns a match into content. |
LayoutFn |
Layout function shape. |
RenderPage
type RenderPage = (match: MatchResult) => unknown;
How an outlet turns a match into content.
LayoutFn
type LayoutFn = (match: MatchResult, children: unknown) => unknown;
Layout function shape. Receives the current match and the inner content (the page, or a nested layout). Layouts compose outermost-first.
router
ScrollBehavior |
|
RouterOptions |
|
RouterBinding |
A router store as signals. |
useRouter |
Use a router in an element. |
ScrollBehavior
type ScrollBehavior =
| "top"
| "preserve"
| "restore"
| ((prev: MatchResult, current: MatchResult) => void);
RouterOptions
interface RouterOptions
manageTitle?: boolean |
Mirror the router's title to document.title. Defaults to true. Turn off when the host page owns the title. |
scrollBehavior?: ScrollBehavior |
How to reset scroll after each nav. Defaults to "top". A function gets (prev, current) and scrolls however it wants. |
RouterBinding
interface RouterBinding
A router store as signals.
readonly store: RouterStore |
|
readonly match: Computed<MatchResult> |
The current match. |
readonly title: Computed<string> |
The current title. |
readonly go: (input: Input, options?: GoOptions) => MatchResult |
|
readonly get: (name: string) => Route |
Look up a route by name. |
useRouter
function useRouter(source?: RouterStore | RouterStoreConfig, options: RouterOptions = {}): RouterBinding
Use a router in an element. Call it in the element's setup.
Given a config, it creates the router, makes it the page's router, keeps
document.title and scroll in step with it, and destroys it when the
element leaves the page. Given a store, it does the same without owning the
store. Given nothing, it returns the page's router.
define("my-app", () => {
const { match } = useRouter({ routes });
return html`<h1>${() => match.value.route?.name}</h1><diso-outlet></diso-outlet>`;
});
From @diso.io/groutcho-core
Exported as they are in @diso.io/groutcho-core: Component, createBrowserHistory, createMemoryHistory, createRouter, ErrorListener, GoListener, GoOptions, History, Input, InputObject, MatchResult, Params, RedirectResult, RedirectTest, Route, RouteConfig, RouteError, RouteInput, Router, RouterConfig, RouteRedirect, RouterStore, RouterStoreConfig, StoreListener, TitleListener, TitleValue.