Skip to content

API reference

Types

TypeDescription
RouteConfig{ path: string; Component: ComponentWithGetData; isSSR: boolean; sitemap?: SitemapRouteConfig }
ComponentWithGetDataReact component type with optional getData?: (params?: { routeParams: Record<string, string>; searchParams: Record<string, string>; request?: unknown }) => Promise<Record<string, unknown>>
RouteDataStateRecord<string, Record<string, unknown>> (routeKey → data)
InitialRouteShape{ path: string } (minimal shape for initial route)

Registry

FunctionDescription
registerRoutes(routes: RouteConfig[])Set the route list (call once on client and in entry-server).
getRoutes(): RouteConfig[]Read the current route list (used internally).

Router (RouterService)

MethodDescription
RouterService.matchRoute(pathname: string)Returns the RouteConfig that matches the pathname.
RouterService.routeParams(routePath: string, pathname?: string)Returns { routeParams, searchParams }; path segments (e.g. /video/:id + /video/123routeParams: { id: '123' }).
RouterService.searchParams(urlOrSearch: string)Parses query string into Record<string, string>.
RouterService.isSsrRoute(pathname: string)Returns whether the pathname matches a route with isSSR: true.
RouterService.matchPath(pathPattern: string, pathname: string)Low-level path match.

Route data context

ExportDescription
RouteDataProviderProvider with initialData, initialRoute, initialParams.
useRouteData()Returns { data: RouteDataState; setData(routeKey, value) }.
buildRouteKey(path, routeParams, searchParams?)Builds a stable key for path + route params + optional search params (so the same path with different query strings gets different keys).

UI components

ComponentDescription
AppRoutesRenders <Routes> from the registry; uses context for page data. Use inside RouteDataProvider (or BrowserRouteDataProvider).
BrowserRouteDataProviderReads window.__PRELOADED_DATA__ and pathname, wraps children in SEOProvider + RouteDataProvider. Use inside BrowserRouter.
SEOSets meta tags and optional JSON-LD for a page. Props: title, description, image?, url?, type?, noindex?, structuredData?. See SEO guide.

SSR (main package)

ExportDescription
render(url: string, options?: RenderOptions)Returns Promise<{ html: string; preloadedData; helmet? }>. options.wrap can wrap the inner tree (e.g. QueryClient, Toaster). options.requestContext is forwarded to getData via params.request. When pages use <SEO />, helmet contains title, meta, link, and script tags for server injection (built from SEO props, no external lib).

Server (lovable-ssr/server)

Import from lovable-ssr/server so Node/Express are not bundled in the client.

ExportDescription
createServer(config: CreateServerConfig)Returns Promise<{ getApp(); listen(port?, callback?) }>.
runServer(config?)Convenience: creates server and calls listen (uses process.cwd() and env if config omitted).

CreateServerConfig

FieldTypeDescription
rootstringProject root (where index.html and dist/ live).
entryPathstringPath to the app’s entry-server module relative to root (e.g. src/ssr/entry-server.tsx).
portnumber?Default port (default 5173).
cssLinkInDevstring?HTML snippet to inject before </head> in dev (e.g. link to /src/index.css).
extraRoutes(app: Express) => voidOptional. Called before the SSR catch-all; use for custom routes.
sitemap{ siteUrl: string }Optional. Enables /sitemap.xml and /robots.txt built from routes with sitemap.include.

Production entry path is derived from entryPath by replacing src/ with dist/ and the extension with .js (e.g. dist/ssr/entry-server.js).