A page is a .tsrx file in pages/, and its path there is the
One address in your app, and the page file that answers it.In the glossary
it answers.
export default functionAboutfunction About(): Element() @{@{ · Statement containerHolds instructions: setup lines, then the element to show. <h1<h1> · HTML elementThe top-level heading.>About the shop</h1<h1> · HTML elementThe top-level heading.>}
The file's path, pages/about.tsrx, makes the address /about. Its default export is what the browser shows there.
A file's path is its address
Each file in pages/ is a route: one address your app answers.
index.tsrx answers /, and about.tsrx answers /about and /about/.
A folder adds a part: blog/[slug].tsrx answers /blog/ plus one part.
An address with no file shows 404.tsrx, with status 404.
Drag a file into pages/, then out again.
about.tsrx makes /about[slug].tsrx makes /blog/hellotype a slug
An editor window shows a pages/ folder holding index.tsrx and an empty blog/ folder. Two files wait on the desk: about.tsrx and [slug].tsrx. Beside it, a browser shows the address /. Drag about.tsrx into pages/, or press it, and the browser goes to /about and shows the About page. Drag [slug].tsrx into blog/ and the browser goes to /blog/hello, with hello pencilled over [slug]. Type in the address bar to change the slug. Take a file back out, and its address shows a 404 page.
[slug] is a blank the address fills
A bracket in a file name is a param. Type a slug in the drawing's address bar to fill it.
import type { PageProps } from '@markless/router';export default functionPostfunction Post({ params }: PageProps<{ slug: string; }>): Element({ params(parameter) params: Readonly<{ slug: string; }> }:PagePropsPageProps · Page propsThe props the router hands a page: params from the bracketed parts of the path, url, status, and http, the request and response, on the server only.<{ slug(property) slug: string: string }>) @{@{ · Statement containerHolds instructions: setup lines, then the element to show. <h1<h1> · HTML elementThe top-level heading.>Post {params.slug}</h1<h1> · HTML elementThe top-level heading.>}
/blog/hello shows Post hello.
docs/[...slug].mdx catches one part or more, as one string like guide/intro.
A plain name beats [param], and [param] beats [...rest].
A page can answer with a status
Every page gets four props: params, url, status and http. Set http.response.status to answer 404 for a missing invoice.
import type { PageProps } from '@markless/router';import { findInvoice } from '../../src/invoices.ts';export default functionInvoicefunction Invoice({ params, http }: PageProps<{ id: string; }>): Element({ params(parameter) params: Readonly<{ id: string; }>, http(parameter) http: HttpContext<AppLocals>The request and the response being written, the same object API routes and middleware get. It exists only while the page renders on the server: the compiler refuses any read of it from code that runs in the browser. Set http.response.status and http.response.headers before the first byte is sent; a later write that changes them throws MARKLESS_ROUTER_RESPONSE_COMMITTED. }:PagePropsPageProps · Page propsThe props the router hands a page: params from the bracketed parts of the path, url, status, and http, the request and response, on the server only.<{ id(property) id: string: string }>) @{@{ · Statement containerHolds instructions: setup lines, then the element to show. constinvoiceconst invoice: any =findInvoiceimport findInvoice(params.id); if (!invoice) http.response.status = 404; <h1<h1> · HTML elementThe top-level heading.>{invoice ?invoice.titleany: 'No such invoice'}</h1<h1> · HTML elementThe top-level heading.>}
Set it before anything the page waits on, because the status leaves with the first bytes.
http exists only on the server, so read it in the page body, never in a handler (why the build stops).