getServerData on every request, getStaticData at build time, or fetch from a client component. Each one has its place.
Examples below use the default app router. Set router: "pages" in veryfront.config.ts to switch to the pages router.
Prerequisites
- A project with at least one page (see Pages and routing).
- A data source you can call from server code, build-time scripts, or the browser (REST API, database, or in-memory data).
Server data
getServerData runs on every request. Use it when data depends on the request (auth, query params, cookies):
veryfront dev and open http://localhost:3000/dashboard?name=Grace. The page should render Welcome, Grace.
The DataContext provides:
| Property | Type | Description |
|---|---|---|
request | Request | The incoming HTTP request |
params | Record<string, string> | Route parameters (e.g. { slug: "hello" }) |
query | URLSearchParams | Query string parameters |
Static data
getStaticData runs at build time. Use it for content that doesn’t change per request:
getStaticData with getStaticPaths to tell the framework which pages to generate.
Redirects and 404s
Returnredirect() or notFound() from any data function:
redirect() accepts an optional second argument for permanent redirects:
Client-side fetching
For data that loads after the page renders, fetch in a client component:Verify it worked
- For
getServerData, hit the page withcurl http://localhost:3000/<path>and confirm the response contains the value you returned inprops. - For
getStaticData, runveryfront buildand inspect the generated HTML for the page. The HTML should contain the static value rather than a client-side fetch loop. - For client-side fetching, open the browser dev tools network tab. The request should fire after the page paints and the rendered output should match the response.