Naalya Handbook

Routing and pages

React Router v7 framework mode on the website. One manifest, the route-module exports this site uses, SSR through TanStack Query, and typegen.

A URL exists only because app/routes.ts lists it. Dropping a file into app/routes/ does nothing, and the filename never becomes the URL. The site runs React Router v7 in framework mode: the @react-router/dev Vite plugin compiles the manifest, server-renders, and generates types. There is no createBrowserRouter.

FileRole
app/routes.tsThe route list, checked with satisfies RouteConfig
app/root.tsxThe <html> document, providers, root loader and the 404 ErrorBoundary
app/routes/_layout.tsxSite chrome around every page
react-router.config.ts{ ssr: true }

The manifest

app/routes.ts (shape)
export default [
  layout("routes/_layout.tsx", [
    index("routes/landing.tsx"),
    route("/about", "routes/about.tsx"),
    route("/blog/:postSlug", "routes/blog-post.tsx"),
    // ...other pages, then legacy 301s such as /admission and /naalya-ai/*
  ]),
  route("/api/form-submission", "routes/api/form-submission.ts"),
  route("/sitemap.xml", "routes/sitemap.ts"),
] satisfies RouteConfig;
KindRoutes
Pages inside the layout/, /about, /admissions, /education-hub, /leadership, three /campuses/*, /contact-us, /settings, /updates, /blog/:postSlug, /terms, /privacy
Legacy 301s inside the layout/lugazi-campus, /lugazi-about-us, /namugongo-campus, /namugongo-about-us, /bweyogerere-campus, /bweyogerere-about-us, /about-us, /admission, and /naalya-ai/* (to /?chat=open)
Resource routes, no UIPOST /api/form-submission, /sitemap.xml

:postSlug is the only named param. The manifest doesn't use prefix.

What a route module exports

This site uses a small part of the framework's exports:

ExportUsedNotes
Default componentEvery pageReceives typed loaderData as a prop; useLoaderData() is never used
loaderMost pagesServer only
metaMost pagesTitle, description, Open Graph, Twitter
links, ErrorBoundaryroot.tsx only
action, clientLoaderNeverForms post to the API and then /api/form-submission; see Forms

Loaders come in three shapes

Content page. Prefetch into a per-request QueryClient and return the dehydrated cache, not the data:

app/routes/landing.tsx
export async function loader() {
  const queryClient = getQueryClient();
  await Promise.all([
    queryClient.prefetchQuery(LandingOptions.landingData()),
    queryClient.prefetchQuery(CampusListOptions.campusListData()),
  ]);
  return { dehydratedState: dehydrate(queryClient) };
}

Dynamic page. Same, then read the cache back and throw a 404 if empty:

app/routes/blog-post.tsx
const post = queryClient.getQueryData(["blog-post", slug]);
if (!post) throw new Response("Post not found", { status: 404 });

Redirect. return redirect("/admissions", { status: 301 }) and a component that renders null.

Two more loaders sit above the pages: root.tsx calls the Sanity client directly for site settings (favicon and document shell), and _layout.tsx prefetches site settings and the footer so the navbar and footer render CMS content in the server HTML.

SSR is a dehydrate and hydrate handshake

So loaderData is { dehydratedState }, not your DTO. The page component wraps its content in <HydrationBoundary state={loaderData.dehydratedState}>, and inner components read through TanStack Query hooks. The server makes a new QueryClient per request; the browser keeps one. More on How it's built and Querying with GROQ.

meta() has to dig through the cache

Because loaders return a dehydrated cache, meta finds its data by comparing JSON.stringify(queryKey) against data.dehydratedState.queries. A key that doesn't match exactly gives undefined and the default title, silently. blog-post.tsx also renders its own <title> in the component, so it sets metadata twice.

Render tree and 404s

/blog/some-post
root.tsx          <html>, <Meta/>, <Links/>, providers, <Scripts/>
└─ _layout.tsx    Navbar, banner, chat widget, seasonal effect, Footer
   └─ blog-post.tsx

A 404 comes from a loader throwing a 404 Response or from an unmatched URL. Both reach the root ErrorBoundary, which shows a styled page with a countdown back to /.

  • Internal links use <Link to="..." viewTransition>.
  • useNavigate() is used in root.tsx (the 404 countdown) and on the Namugongo campus page; redirect() handles the 301s.
  • NavLink is never used. navbar.tsx styles the active link from useLocation().pathname with === and .includes(), which can match substrings by mistake. Follow that pattern but watch for collisions.

Typegen

Every route imports import type { Route } from "./+types/<name>". That path resolves because tsconfig.json sets rootDirs: [".", "./.react-router/types"], overlaying the generated tree. It gives Route.LoaderArgs, Route.ComponentProps, Route.MetaArgs, and in root Route.LinksFunction and Route.ErrorBoundaryProps.

Run typegen after routing changes

.react-router/ is gitignored. On a fresh clone, or after editing routes.ts, every ./+types/... import shows as missing until typegen runs. pnpm dev, pnpm build and pnpm typecheck (react-router typegen && tsc) all run it. The build sets NODE_OPTIONS=--max_old_space_size=4096 because the bundle is large.

To add a route: add a line to routes.ts, create the module, run typegen. Recipes are on Adding a page.

On this page