Dion Boles

Full Stack Engineer · Healthcare & FHIR


Posts tagged #react-router

A static blog with React Router: prerender every page

React Router can generate plain HTML files at build time, so a blog like this needs no server. In framework mode you turn off server rendering and list the paths to prerender:

import type { Config } from "@react-router/dev/config";

export default {
  ssr: false,
  prerender: ["/", "/about", ...posts.map((p) => `/post/${p.id}`)],
} satisfies Config;

A few things I ran into:

Only prerendered routes can have a loader, so my catch-all 404 route has none and just throws a 404 response from the component.

In React Router v8 the meta function receives loaderData, not data. I had every post titled “Not found” until I changed that.

The build writes about 100 HTML pages plus a __spa-fallback.html. I copy that file to 404.html after the build so unknown URLs show the site's 404 page.

Styling is Tailwind v4 with CSS variables for the colors, so the monthly accent and dark mode are just a different set of variables on the html element.

I moved my blog off Tumblr and rebuilt it myself

I've moved this blog off Tumblr. dionboles.me is now a static site that I build and host myself, instead of a theme running on someone else's platform.

I had a backup of my posts on my laptop, so the move was mostly a matter of rebuilding the site around them. It's a small React Router project: the 40 posts from the backup, the same design I had been building for the Tumblr theme, a monthly accent color, dark mode, and highlighted code blocks with a copy button.

The importer reads only the exported post HTML, cleans it up, and writes one JSON file. Photos are copied over only if a post uses them. Along the way I fixed code blocks that Tumblr had split into one paragraph per line.

The upside of owning the site is that I control the design, the URLs and the backups. Posts are now just entries in a file, so adding one is a quick edit and a deploy.

← All posts