CodeBlanks Logo Icon CodeBlanks

Layout with Outlet

Learn to use a shared layout with React Router.

Layout with Outlet

Outlet marks where React Router renders child routes. You place an Outlet tag inside the layout; the router renders the matched child there.

This is cleaner than passing the children prop manually. The layout does not know which child to render; the router matches automatically.

Multiple Outlets are also possible; useful for named views. But for the common case a single Outlet is enough.

Multiple child routes

A layout can support multiple child routes. For example, a Dashboard layout may have stats, settings and users children; each renders at the Outlet.

Child routes nest inside the parent. The path prefix is joined automatically: stats becomes /dashboard/stats.

This pattern keeps large panels organized; each section lives in its own component.

Practice Dashboard layout

Complete the skeleton below. Write a Dashboard component; return a div containing <Sidebar /> and <Outlet />. Export it.

Starter code

App.jsx
import { Outlet } from "react-router-dom";

// Write the Dashboard component here

Sample solution

App.jsx
import { Outlet } from "react-router-dom";

function Dashboard() {
  return (
    <div>
      <Sidebar />
      <Outlet />
    </div>
  );
}

export default Dashboard;

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 What does Outlet do?

  • Renk verir
  • State tutar
  • Fetches data
  • Renders the child route Correct answer

Explanation: Outlet marks where the matched child route renders.

2 Outlet element

Question
function Layout() {
  return <div><Sidebar /><____ /></div>;
}
Answer
function Layout() {
  return <div><Sidebar /><Outlet /></div>;
}

Explanation: Outlet renders the child route.

3 Layout with Outlet: match the terms

Term Meaning
Outlet Child route position
Dashboard Parent layout
stats Child path
Sidebar Left menu

All lessons in Intermediate