Purpose of Outlet in React Router v6 nested routes
Nested routing layout knowledge.
Outlet renders the matched child route inside a parent layout, enabling shared chrome with swappable content; configure nested routes and place Outlet where children render.
WHAT THIS TESTS Your understanding of React Router v6's nested route model and the mechanism that lets a parent layout host whichever child route currently matches.
A GOOD ANSWER COVERS Outlet is a component you render inside a parent route's element to mark the spot where the matched child route should be displayed. It enables layout routes: the parent renders shared UI such as a header, sidebar, or tab strip, and Outlet renders the active child. This avoids duplicating the layout in every page. You configure it by nesting child route objects or Route elements under a parent route. When a child path matches, React Router renders the parent element, and wherever that element places Outlet, the child element appears. Outlet can also pass data to children via the context prop, read with useOutletContext.
COMMON WRONG ANSWERS Confusing Outlet with the React children prop; children come from JSX composition, while Outlet comes from route matching. Putting the full layout inside each leaf page. Forgetting that an index route fills the Outlet when the parent path matches exactly. Thinking Outlet requires manual prop drilling of the active route.
LIKELY FOLLOW-UPS What renders in the Outlet when only the parent path matches? That is the index route. How do you share data into children? useOutletContext. How does this compose multiple layout levels? What about a default fallback?
ONE CONCRETE EXAMPLE A settings area uses a parent route at /settings whose element is a SettingsLayout with a left nav and an Outlet. Child routes profile, security, and billing are nested under it. SettingsLayout renders the persistent nav plus the Outlet. Navigating to /settings/security keeps the nav fixed while the Outlet swaps in the SecurityPanel; an index child can render a profile summary when the user is at /settings exactly. One layout, three swappable sub-sections, no duplicated chrome.
Read the original → reactrouter.com
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.