API Reference
@domphy/router is a 1-1 port of @tanstack/router-core v1.171.13 — every export below has identical behavior to upstream, so the TanStack Router reference documents each item in full detail. The only additions are the create* adapter functions and the re-exported @tanstack/history.
Creating Routers And Routes
| Export | Purpose |
|---|---|
createRouter(options) | Create the router. Key options: routeTree, history, context, defaultStaleTime, defaultPreloadStaleTime, defaultGcTime, parseSearch / stringifySearch, scrollRestoration |
createRoute(options) | Create a route: getParentRoute, path (or id for pathless layouts), validateSearch, beforeLoad, loader, loaderDeps, staleTime, gcTime, shouldReload |
createRootRoute(options?) | Create the root of the tree |
createRootRouteWithContext<T>() | Root route factory with a required typed router context |
RouterCore, BaseRoute, BaseRootRoute | The underlying classes (advanced — the create* functions wrap them) |
Router Instance
The main members of the router returned by createRouter:
state—RouterState:matches,location,resolvedLocation,status("pending" | "idle"),isLoading,statusCode,redirectnavigate(options)— navigate; resolves when loaders settlebuildLocation(options)— resolve navigate options to aParsedLocationwithout navigatingload()— match and load the current location (call once at startup, and on the server)subscribe(event, fn)— lifecycle events:onBeforeNavigate,onBeforeLoad,onLoad,onResolved,onBeforeRouteMount,onRenderedinvalidate(options?)— mark cached loader data stale and re-run active loaderspreloadRoute(options)— run matching + loaders for a destination ahead of navigationmatchRoute(location, options?)— test a location against the tree ({ fuzzy, includeSearch })getMatch(matchId)/clearCache(options?)— cache access (advanced)history— the underlyingRouterHistory(back,forward,go,block)update(options)— update router options after creation
History
Re-exported from @tanstack/history:
createBrowserHistory(),createHashHistory(),createMemoryHistory({ initialEntries }),createHistory()parseHref(href, state)- types:
RouterHistory,HistoryLocation,ParsedHistoryState,NavigationBlocker,BlockerFn
Control Flow
redirect(options)/isRedirect/isResolvedRedirect/parseRedirect— throwable redirect Responses forbeforeLoadand loadersnotFound(options?)/isNotFound— throwable not-found errorsdefer(promise)/TSR_DEFERRED_PROMISE— deferred loader data with synchronous status
Search Params
retainSearchParams(keys | true)/stripSearchParams(input)— search middlewaresdefaultParseSearch/defaultStringifySearch— the JSON-aware default codecparseSearchWith(parser)/stringifySearchWith(stringifier)— build custom codecsSearchParamError,PathParamError— validation error classes
Scroll Restoration
setupScrollRestoration(router)— wire scroll save/restore (client)getScrollRestorationScriptForRouter(router)— inline pre-hydration script, from@domphy/router/scroll-restoration-scriptdefaultGetScrollRestorationKey,storageKey
Path Utilities
interpolatePath,resolvePath,joinPaths,cleanPath,trimPath/trimPathLeft/trimPathRight,removeTrailingSlash,exactPathTestencode/decode— query-string primitives (qss)rootRouteId— the id of the root route ("__root__")
Utilities
functionalUpdate,replaceEqualDeep,deepEqual,isPlainObject,isPlainArray,hasKeyscreateControlledPromise,isModuleNotFoundError,escapeHtml,isDangerousProtocoldefaultSerializeError,getLocationChangeInfo,lazyFn,isMatch
SSR Entry Points
| Entry | Main exports |
|---|---|
@domphy/router/ssr/server | createRequestHandler, attachRouterServerSsrUtils, transformStreamWithRouter, transformReadableStreamWithRouter, transformPipeableStreamWithRouter, createSsrStreamResponse, defineHandlerCallback, getOrigin, getNormalizedURL |
@domphy/router/ssr/client | hydrate, json, mergeHeaders |
@domphy/router/isServer | isServer boolean, resolved per build condition |
See SSR for how these fit Domphy.
Types
All public types are re-exported, including:
- routes:
AnyRoute,Route,RouteOptions,RootRoute,RouteIds,RouteById,RoutePaths - router:
AnyRouter,RouterOptions,RouterState,RouterEvents,Register,RegisteredRouter - matches:
AnyRouteMatch,RouteMatch,MakeRouteMatch - navigation:
NavigateOptions,ToOptions,LinkOptions,ParsedLocation,ViewTransitionOptions - loading:
LoaderFnContext,RouteLoaderFn,DeferredPromise - search:
SearchMiddleware,SearchValidator,SearchParser,SearchSerializer - control flow:
Redirect,RedirectOptions,NotFoundError - ssr:
DehydratedRouter,DehydratedMatch,Manifest,RequestHandler