Pathless Routes for Shared Layouts
You'll learn how to create layout routes that wrap multiple children without adding segments to the URL.
The Problem: Layouts Without URL Clutter
Sometimes you want several routes to share a common layout (header, sidebar, error boundary, authentication check) but don't want the layout itself to appear in the URL. For example, /products and /orders might both need an authentication wrapper, but you don't want /auth/products or /dashboard/orders — just the clean paths themselves.
The Solution: Routes Without a path
React Router allows you to define a route without a path prop. These "pathless routes" act purely as wrappers — they render an <Outlet /> for their children but contribute nothing to the URL structure.
<Route element={<AuthLayout />}>
<Route path="/products" element={<Products />} />
<Route path="/orders" element={<Orders />} />
</Route>
Notice the parent route has no path. Both /products and /orders will render inside <AuthLayout />, but the URL remains exactly /products and /orders — no extra segments.
When to Use Pathless Routes
- Authentication wrappers that check login status across multiple routes
- Error boundaries shared by a group of routes
- Common providers (theme, data context) for specific sections
- Layout components that shouldn't be tied to a URL segment
This keeps your URL structure clean while maintaining component hierarchy for shared logic.
Key Takeaway: Pathless routes (routes without a path prop) let you group children under a shared layout or wrapper without affecting the URL, perfect for authentication, error boundaries, or other cross-cutting concerns.