Hierarchical UI Composition with Remix Nested Routes
Nested Remix routes let you compose UI hierarchically by placing child route files inside parent folders, enabling shared layouts and per‑segment data loading.
02 Sept 2026, 07:42 UTC

Useful Answer
You can compose UI hierarchically by nesting route files under a parent route folder; the URL path becomes the parent path plus the child segment, and each nested route can run its own loader or action before rendering.
How Nested Routes Work
In Remix, a route is defined by a file located inside a route folder. The file path determines the URL segment. When a child route file lives inside a parent route folder, the child’s URL is the parent’s URL followed by the child segment. This allows shared layouts and data loading per segment without duplicating code.
The parent route typically exports a component that renders an <Outlet /> element where the child route’s UI is inserted. The parent can also provide layout components that wrap the child content.
Worked Configuration Example
// app/dashboard.jsx – parent route
import { Outlet } from "@remix-run/react";
export default function Dashboard() {
return (
Dashboard
);
}
// app/dashboard/settings.jsx – child route
import { useLoaderData } from "@remix-run/react";
export async function loader({ params }) {
// Simulate server‑side data fetch
const response = await fetch("/api/settings");
const data = await response.json();
return { data };
}
export default function Settings() {
const { data } = useLoaderData();
return (
Settings
{JSON.stringify(data, null, 2)}
);
}
Running the dev server and navigating to /dashboard shows the dashboard layout. Visiting /dashboard/settings triggers the loader for the child segment, then renders the Settings component inside the dashboard layout.
Verification Steps
- Start the development server with
npm run dev. This command requires Node.js and write permission to the project directory. - Open a browser and go to
/dashboard. The console should display a single loader call for the parent route (if any) and no child loader. - Navigate to
/dashboard/settings. The console should now show two loader invocations: one for the parent (if it defines a loader) and one for the childloader. - Run
npx remix-routes(or inspect theremix-routesplugin UI) to confirm the file‑system hierarchy matches the rendered route tree.
Practical Limits
- Performance: Each nested route incurs its own data loading cycle. Deep nesting (more than 3–4 levels) can increase round‑trips and degrade perceived speed.
- Maintainability: Very deep trees become hard to read and to reason about, especially when state is shared across many levels.
- File structure: Every nested route file must export a default component and any required data functions. Missing exports cause runtime errors such as “Cannot read property '...' of undefined”.
Common Mistakes
- Absolute URLs in
<Link>. Usinghref="/dashboard/settings"inside a child component forces a full page reload instead of client‑side navigation, breaking the hierarchical benefit. - Forgotten exports. If the child route does not export a
loader,action, or default component, the route will not match the URL and you’ll see a 404. - Naming mismatches. The child folder name must match the URL segment. For example, a folder named
settingscreates the segment/settings. A mismatch leads to 404 errors.
Risks and Mitigations
Deep nesting (>4 levels) can cause slower load times and make state management difficult. To mitigate, keep the hierarchy shallow, extract shared logic into utilities or context providers, and test each segment independently.
Client‑side navigation for sensitive operations (e.g., form submissions) should use action with proper CSRF protection rather than relying on Link alone, because Link only triggers navigation without server validation.
Summary
Nested routes in Remix let you build UI hierarchies by placing child route files inside parent route directories. This structure enables shared layouts via <Outlet />, per‑segment data fetching with loader or action, and type‑safe data access through useLoaderData and useActionData. Keep nesting depth reasonable, export all required functions, avoid absolute navigation links, and verify the hierarchy with the dev server and the remix-routes tool.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.