Skip to main content
Veryfront pages can load data three ways: 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):
Run veryfront dev and open http://localhost:3000/dashboard?name=Grace. The page should render Welcome, Grace. The DataContext provides:

Static data

getStaticData runs at build time. Use it for content that doesn’t change per request:
For dynamic routes, pair getStaticData with getStaticPaths to tell the framework which pages to generate.

Redirects and 404s

Return redirect() 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 with curl http://localhost:3000/<path> and confirm the response contains the value you returned in props.
  • For getStaticData, run veryfront build and 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.