app/ (or pages/) define routes; layouts compose down the tree; brackets in path segments mark dynamic params.
Examples below use the default app router. Set router: "pages" in veryfront.config.ts to switch to the pages router.
Prerequisites
- A project created with
veryfront init(see Create project). - The dev server is the easiest way to test routes:
veryfront dev.
Router equivalents
Veryfront supports both router styles. The main difference is file shape:
Use the app router when you want the newer directory-per-route shape. Use the pages router when you want the flatter file-per-route layout.
Basic pages
veryfront dev and open http://localhost:3000. The page should render Welcome.
Layouts
Layouts wrap pages and persist across navigation. Createlayout.tsx at any level:
/dashboard/settings renders inside both the root layout and the dashboard layout.
layout.tsx and the other supported layout.* extensions are reserved layout metadata at every
directory level in both routers. They wrap descendant pages and never create a /layout route.
Overriding or disabling a layout
A page can opt out of the nested layout chain, or replace it with a named layout. On.md/.mdx pages, set layout in the frontmatter:
.tsx/.jsx/.ts/.js pages, export a layout constant:
frontmatter object:
frontmatter.layout property accepts the same false and named-layout values as the direct
layout export.
Supported values in both cases:
layout: falserenders the page bare: no ancestor layouts, no default layout.layout: "name"replaces the entire nested chain with the named layout. Ancestor layouts (including the root layout) are not applied.
@/layouts/custom.tsx or
@components/CustomLayout.tsx, loads that file directly, without falling back to
convention-based discovery. Plain names resolve from, in order:
layouts/<name>.{tsx,mdx,md,jsx,ts,js}- anything inlayouts/is a layout.components/<Name>Layout.*orcomponents/Layout.*.
layout in veryfront.config.ts; a page’s
layout frontmatter or export always wins over the config default.
Dynamic routes
Use brackets for dynamic segments:usePageContext hook:
Post: hello.
Catch-all routes
Use[...segments] to match multiple path segments:
MDX pages
Rename any page to.mdx to write content in Markdown with JSX:
usePageContext() from veryfront/context:
Override rendered MDX elements
Wrap an MDX page or layout withMDXProvider to replace generated elements:
useMDXComponents(localOverrides) when a component
needs the effective map; local entries take final precedence.
MDXProvider supplies application-owned React components to already compiled
MDX. It does not compile or sanitize arbitrary strings. Render runtime Markdown
strings with veryfront/markdown.
Reading server data from a layout or nested component
A page’sgetServerData props are passed to the page
component. To read them from a layout or a deeply-nested component without
prop-drilling, use usePageContext().data:
data is the object your page returned as getServerData’s props. It is
populated identically on the server render, in the hydration markup, and after
client-side navigation. A page without getServerData sees an empty object.
Client components
By default, components render on the server. Add'use client' to make a component interactive:
Navigation
Use theLink component for client-side navigation:
prefetch={false} when a link must not prefetch.
Programmatic navigation:
Reading the live location
useRouter() is the single hook for location and navigation. Its pathname,
query, and params update reactively on client-side navigation:
shouldRevalidate
option.
Verify it worked
Start the dev server and request each page you added:HTTP/1.1 200 OK. Visit the same URLs in a browser
to confirm the React component renders without console errors.