API Reference

App

createApp(routes, options?) / DomphyApp

MemberMeaning
app.routerthe 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

MemberMeaning
stateRecordState with pathname, search, hash, params, status, error — all reactive
treeState<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) — receive RouteContext: 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?
  • redirect(to) / permanentRedirect(to) — throw, restart navigation at to
  • notFound() — throw, render the nearest not-found boundary
  • rewrite(to) — returned from middleware, render to under the original URL
  • RedirectSignal / NotFoundSignal — the thrown classes, for custom catch logic

Patches & Blocks

  • navLink({ href, prefetch?, replace?, scroll?, exact?, router? })a patch, see Navigation
  • optimizedImage({ src, width?, height?, fill?, sizes?, quality?, priority?, placeholder?, blurDataURL?, loader?, deviceSizes? })img patch, see Image & Script
  • script({ src, strategy?, id?, async?, onLoad?, onError? }) — script block, see Image & Script

Metadata

  • Metadata type — see Metadata for fields
  • resolveMetadata(values, context) — merge a segment chain
  • metadataToHeadTags(resolved) — flat head tag descriptions
  • renderHeadTags(tags) — HTML string (SSR)
  • applyHeadTags(tags) — write document.head

API Routes

  • createApiHandler(routes)(request: Request) => Promise<Response>
  • json(data, init?) — JSON response shorthand
  • ApiRoute: path + GET/POST/PUT/PATCH/DELETE/HEAD/OPTIONS handlers (request, { params })

Lower Level

  • compileRoutes(routes) / matchRoute(compiled, pathname) / matchPath(segments, pathname) / parseSegment(part) — the matcher
  • buildHref(pattern, params) — fill params into a pattern
  • createBrowserHistory() / createMemoryHistory(initial?) / HistoryAdapter — history backends
  • DataCache — the loader cache (seed, snapshot, invalidate, load, prefetch)
  • buildTree(...) — composes layouts + boundaries (used by the router)