Engineering
The Router I Did Not Install
Two routes do not need a routing library. They need about forty lines and a hydration contract you can state in one sentence.
This site has two route shapes. The feed at `/`, and an article at `/posts/<slug>`. That is the entire routing requirement, and I wrote forty lines for it instead of installing a routing library.
The interesting part is not the forty lines. It is that the route table has to be true in two places at once — at build time and in the browser — and that is the constraint a library would have hidden from me.
A prerendered site has no server to ask
On a server-rendered site the router is resolved per request, so the server is the single source of truth. Here the build step is the server: it walks a list of slugs and writes a directory per slug. The browser then loads one of those files.
That means the route matching has to agree with itself, or a visitor gets a page whose HTML was rendered for a different URL than the one in their address bar. That is not a subtle bug. It is a page that renders twice and looks wrong in between.
The hydration contract, in one sentence
The path is a prop, passed in from outside the component tree, and both renderers receive the same value.
// server: the path is an argument
export function render(path = "/") {
return renderToString(<App initialPath={path} />);
}
// client: the path is read from the address bar
hydrateRoot(root, <App initialPath={window.location.pathname} />);Reading `window.location` inside render would have worked on the client and broken on the server, because the server has no window. Worse, it would have broken silently: the client would render the right thing, just later, after a hydration mismatch warning nobody reads.
Permissive matchers fail loudly
The slug matcher originally only accepted lowercase letters, digits and hyphens. So a request for `/posts/UPPER`, or a typo, matched nothing and fell through to the feed — a 200 at a URL that does not exist, showing seven real-looking articles.
A loose pattern fails loudly. A strict one fails silently into the wrong view.
The fix is to match any single segment and let the data decide what exists. `/posts/UPPER` now reaches the not-found branch, which is honest. A route matcher should do the matching; the content should decide the answer.
Links stay real links
Every internal link is an `<a href>`. Only a plain left click with no modifier keys is intercepted, so cmd-click, middle-click, and "copy link address" all behave the way a browser user expects. A router that rewrites everything into click handlers loses the open-in-new-tab menu for no reason.