API Reference
App
createApp(routes, options?) / DomphyApp
| Member | Meaning |
|---|---|
app.router | the AppRouter instance |
app.element() | root DomphyElement; the route tree renders through one reactive child |
app.render(target) | client render: starts the router, renders into target |
app.hydrate(target, style?) | SSR hydration: seeds loader data from bootstrapScript, mounts onto existing DOM |
app.renderToString(url, { headers? }) | server render, returns SSRResult |
app.destroy() | removes the tree and releases history listeners |
AppOptions: history (HistoryAdapter | null, default browser), middleware, notFound, error.
SSRResult: html, css, head, status, redirect?, data, bootstrapScript.
Router
AppRouter
| Member | Meaning |
|---|---|
state | RecordState with pathname, search, hash, params, status, error — all reactive |
tree | State<DomphyElement> of the current route tree |
searchParams(listener?) | current URLSearchParams, reactive |
navigate(href, { replace?, scroll? }) | client navigation |
push(href) / replace(href) | navigation shorthands |
back() / forward() | history traversal |
refresh() | clear the loader cache, re-render the current URL |
prefetch(href) | run target loaders ahead of navigation |
addEventListener(event, callback) | routeChangeStart / routeChangeComplete / routeChangeError; returns a release function |
getMatch() | the current RouteMatch (route chain + params) |
start() / destroy() | lifecycle (called by DomphyApp for you) |
getRouter() returns the most recently created router (used by navLink by default).
Routes
defineRoutes(routes) / Route
path, page, layout, loading, error, notFound, metadata, loader, revalidate, middleware, redirect, permanent, children. See Routing.
Blocks and contexts
PageBlock(context)/LayoutBlock(children, context)— receiveRouteContext:pathname,url,params,searchParams,hash,data,segmentData,headers?LoadingBlock(context),ErrorBlock(error, retry),NotFoundBlock()Loader(loaderContext)—LoaderContext:pathname,url,params,searchParams,headers?Middleware(middlewareContext)—MiddlewareContext:url,pathname,searchParams,headers?
Navigation Control Flow
redirect(to)/permanentRedirect(to)— throw, restart navigation attonotFound()— throw, render the nearest not-found boundaryrewrite(to)— returned from middleware, rendertounder the original URLRedirectSignal/NotFoundSignal— the thrown classes, for custom catch logic
Patches & Blocks
navLink({ href, prefetch?, replace?, scroll?, exact?, router? })—apatch, see NavigationoptimizedImage({ src, width?, height?, fill?, sizes?, quality?, priority?, placeholder?, blurDataURL?, loader?, deviceSizes? })—imgpatch, see Image & Scriptscript({ src, strategy?, id?, async?, onLoad?, onError? })— script block, see Image & Script
Metadata
Metadatatype — see Metadata for fieldsresolveMetadata(values, context)— merge a segment chainmetadataToHeadTags(resolved)— flat head tag descriptionsrenderHeadTags(tags)— HTML string (SSR)applyHeadTags(tags)— writedocument.head
API Routes
createApiHandler(routes)—(request: Request) => Promise<Response>json(data, init?)— JSON response shorthandApiRoute:path+GET/POST/PUT/PATCH/DELETE/HEAD/OPTIONShandlers(request, { params })
Lower Level
compileRoutes(routes)/matchRoute(compiled, pathname)/matchPath(segments, pathname)/parseSegment(part)— the matcherbuildHref(pattern, params)— fill params into a patterncreateBrowserHistory()/createMemoryHistory(initial?)/HistoryAdapter— history backendsDataCache— the loader cache (seed,snapshot,invalidate,load,prefetch)buildTree(...)— composes layouts + boundaries (used by the router)