One address in your app, and the page file that answers it.In the glossary
in your app, and the build checks that the route exists.
import { Link } from '@markless/router';export default functionHomefunction Home(): Element() @{@{ · Statement containerHolds instructions: setup lines, then the element to show. <nav<nav> · HTML elementA group of navigation links.> <LinkLink · Route linkRenders a plain <a href>. Give it a route pattern and params, and the build writes the real address and checks it against your routes. A click swaps in the next page without a full reload.href(property) href?: string | undefined="/about">About</LinkLink · Route linkRenders a plain <a href>. Give it a route pattern and params, and the build writes the real address and checks it against your routes. A click swaps in the next page without a full reload.> <LinkLink · Route linkRenders a plain <a href>. Give it a route pattern and params, and the build writes the real address and checks it against your routes. A click swaps in the next page without a full reload.href(property) href?: string | undefined="/blog/[slug]"params(property) params: { slug: string; }={{ slug: 'hello' }}> First post </LinkLink · Route linkRenders a plain <a href>. Give it a route pattern and params, and the build writes the real address and checks it against your routes. A click swaps in the next page without a full reload.> </nav<nav> · HTML elementA group of navigation links.>}
Link renders a real <a>. params fills the brackets, so the build writes the second link as href="/blog/hello".
The build checks every link
/blog/[slug] is a route pattern: a file path in pages/, with brackets for the parts that change.
A pattern that matches no file in pages/ stops the build.
A pattern without its params stops the build and names them.
A plain address like /about isn't checked by the build. Your editor flags its typos.
Try both keys in the door.
A pen-and-ink door with a lock, and two keys on the desk beside it, named /blog/[slug] and /blgo/[slug]. Press a key, or drag it to the lock. The /blog/[slug] key goes in, turns, and the door opens. The /blgo/[slug] key stops at the lock and slides back, and the door stays shut.
The typo key is the build error you'd see:
Typed route error: /blgo/[slug] does not match any route in pages/.
A click swaps in only the page
An in-place navigation keeps the page you're on and swaps in only its middle.
The address changes when the new middle lands, not at the click.
Back and Forward bring back each page and its scroll.
Plain <a> links to your pages do the same.
Swap the sheet, then try to pull the clip off.
A pen-and-ink clipboard. Under its clip is a sheet with a coffee bean on it, and a strip of tape on the clip reads /. Press the sheet, drag it aside, or use the arrow keys, and a new sheet with a cup on it takes its place while the label re-inks to /about. The board and clip stay. Try to pull the clip off, and it snaps back.
Early fetches are real requests
A pointer resting on a link, a focus or a press starts fetching the next page before the click. That fetch is a real GET, so turn it off for a link that does something:
<LinkLink · Route linkRenders a plain <a href>. Give it a route pattern and params, and the build writes the real address and checks it against your routes. A click swaps in the next page without a full reload.href(property) href: string="/logout"prefetch(property) prefetch: boolean={false}>Log out</LinkLink · Route linkRenders a plain <a href>. Give it a route pattern and params, and the build writes the real address and checks it against your routes. A click swaps in the next page without a full reload.>
The router never fetches other sites or /api/ paths early.
Links with download, a target or rel="external" aren't fetched early either.
router({ prefetch: false }) in vite.config.ts turns early fetches off everywhere.
navigate() is a click from code
import { navigate } from '@markless/router';export default functionCheckoutfunction Checkout(): Element() @{@{ · Statement containerHolds instructions: setup lines, then the element to show. <button<button> · HTML elementA button a person can press.onClickonClick · Event handlerRuns when this element gets the DOM event named after on, with the browser's own event object.={async () => { awaitfetchfunction fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>MDN Reference('/api/orders', { method: 'POST' }); awaitnavigate(alias) navigate(href: string | URL, options?: NavigateOptions): Promise<void>Navigates to href exactly as a click on <Link href={href}> would: a page of this app swaps in place, anything else loads as a document. The promise resolves once the page the user ends up on is in place: at once for the page already shown, and, when a later navigation replaces this one, once that page is shown. A navigation that loads a new document leaves this page, so its promise never settles. Runs in the browser only.('/orders', { replace: true }); }} > Place order </button<button> · HTML elementA button a person can press.>}
navigate() resolves once the new page is in place. replace swaps the current history entry instead of adding one, on navigate() and on Link.