Munchable has one page per condition that answers the list-shaped search: "what foods should I avoid", "food list". There are seven of them now, for example the FODMAP food list, the SIBO diet list and the acid reflux foods to avoid page. They sit at the root of the site, not under a prefix, because the URL is the thing people search for.
That placement is the interesting engineering problem, because the root already belongs to something else.
One root segment, two kinds of page
The site's single-question answer pages ("is X okay for Y") live under one top-level dynamic route, app/[question]/page.tsx. A hub at /fodmap-food-list is a different kind of page that has to live at the same level. Next resolves a static folder ahead of the dynamic segment, so it works, but it works by a convention nothing enforces.
So each hub is a folder with a two-line page.tsx:
export const dynamic = 'error'; export const metadata = foodListMetadata('fodmap-food-list'); export default function FoodListPage() { return <FoodListView slug="fodmap-food-list" />; } dynamic = 'error' makes the build fail if anything in that tree reaches for request data, which keeps the page prerendered. The copy, the title and the description all come from one content module, so the SEO tests that check every title and description cover the hubs for free.
The membership of each list is derived rather than typed. Each page is built from the same data the app uses, so when that data moves, the list moves with it. I will not go into how that data is organised, but the consequence matters for the tests: the page has copy that is written by hand wrapped around a list that is not.
Four invariants
The test file for the hubs is about a hundred lines. It asserts four things, and each one is a way the page could break without a build error.
1. Every answer page for a condition appears on its hub, exactly once. The test computes the expected set of links from the answer pages for that condition, computes what the hub lists, and compares the two sorted arrays. It also checks for duplicates separately, so a failure says "an ingredient is listed twice" and not just "arrays differ". This is the property that makes the hub a real hub rather than a curated sample: nothing a visitor can reach from search is missing from the list.
2. There is a heading for every group the data can produce, and none it cannot. The hand-written part of each hub includes a heading and a paragraph per group. If the underlying data grows a new group, the list would silently drop those entries, since no heading exists to print them under. The test compares the set of headings with the set of group keys the data can return, in both directions, then walks every answer page and asks which group it lands in. A missing heading fails by naming the page.
3. A hub's slug is not an answer page's slug, and its route exists. The two kinds of page share a namespace. The test checks that each hub has a folder on disk and that no answer page uses the same slug. Without it, a future ingredient whose question slug happened to equal a hub slug would shadow one of them with no error.
4. Every condition guide links to its hub, and every condition has one. The guides under /conditions carry a "further reading" list, and the test looks for the hub link in it. That closes the loop: guide to hub, hub to answer pages, answer pages back up to the hub. Coeliac disease is the deliberate exception, because its list already exists as a different page (the hidden gluten reference), and the hub lookup points the answer pages at that instead.
The redirect check that lives in the same file
The hubs arrived in the same change that reworded some question slugs, so the file also holds the redirect tests. Two old URL shapes map to the new ones with pattern rules, and the tests use Next's own bundled copy of the path matching library, so the patterns are exercised exactly as the server exercises them:
- every legacy slug for the affected conditions redirects to the page that replaced it
- no page that currently exists is matched by a redirect, hubs included
That second assertion is the one I would not skip. A redirect rule that matches a live page makes the page unreachable, and it fails quietly: the page is still in the sitemap, still prerendered, and never served.
What I would take from it
When a page mixes written copy with data-derived content, the risky seam is where one moves under the other. A test that iterates the data and asks the page a question about every row is more useful than a snapshot, because it fails with the name of the thing that broke. For a root-level route it also pays to test the namespace, since nothing else does.
You can click through the result: start at the conditions index, open any hub, and follow a row to its answer page. The link back up should be there every time, and the test is why.