LearnFull-stack apps
Routing and layouts
So far every component you wrote lived on one page. A real app has many: a home page, a list, one page per item, a settings section with its own menu. In @weft-js/start you don't configure a router for that. You make files, and the folder they're in is the URL they answer.
This page is about where pages come from and how you move between them. The next one, Loading data, is about what goes in them.
Routes are files
Every file in src/routes is a route. Its path inside that folder is its URL:
src/routes/index.tsx /src/routes/about.tsx /aboutsrc/routes/todos/index.tsx /todossrc/routes/todos/[id].tsx /todos/42, /todos/abc…src/routes/docs/[...rest].tsx /docs/a, /docs/a/b/c…src/routes/_layout.tsx wraps every pagesrc/routes/todos/_layout.tsx wraps every page under /todossrc/routes/404.tsx the not-found pagesrc/routes/_error.tsx the error pageA route's page is the file's default export, an ordinary component. Here is the /about page a new app starts with, with a meta added so the tab and search results say what it is:
// src/routes/about.tsximport type { Meta } from '@weft-js/start'export const meta: Meta = { title: 'About', description: 'Who makes this app, and why.' }export default function About() { return ( <main> <h1>About</h1> <p>A small app for keeping track of what to do next.</p> </main> )}index.tsx is the folder's own page, so todos/index.tsx answers /todos. Files and folders whose names start with _ are left out of the URL table (other than _layout and _error), and so are test files, so you can keep a todos/_parts.tsx of helpers next to the pages that use it.
weft routes prints the table it found, which is handy when a page isn't where you expected:
npx weft routes