0
Fork 0
mirror of https://github.com/TanStack/router.git synced 2026-11-16 19:38:07 +00:00
router/docs/framework/react/guide/outlets.md
Sean Cassiere 9880bb8bb1
docs: use gfm alerts in the documentation (#1924)
* docs: gfm alerts on the deprecated apis

* docs: gfm alerts in the api reference

* docs: gfm alerts in framework/react

* docs: gfm alerts in framework/react/guide

* docs: more gfm alerts in the api reference

* docs: update to the decisions on dx doc
2024-07-10 11:46:21 +12:00

1 KiB

title
Outlets

Nested routing means that routes can be nested within other routes, including the way they render. So how do we tell our routes where to render this nested content?

The Outlet Component

The Outlet component is used to render the next potentially matching child route. <Outlet /> doesn't take any props and can be rendered anywhere within a route's component tree. If there is no matching child route, <Outlet /> will render null.

Tip

If a route's component is left undefined, it will render an <Outlet /> automatically.

A great example is configuring the root route of your application. Let's give our root route a component that renders a title, then an <Outlet /> for our top-level routes to render.

import { createRootRoute } from '@tanstack/react-router'

export const Route = createRootRoute({
  component: RootComponent,
})

function RootComponent() {
  return (
    <div>
      <h1>My App</h1>
      <Outlet /> {/* This is where child routes will render */}
    </div>
  )
}