Skip to content
Source
Sign inSign up
TanStack/router

docs(start): explain parent route outlets #7831

OpencoyaSONG(GitHub profile, opens in a new tab)wants to merge 3 commits intomain fromrefs/pull/7831/headopened

Showing 2 changed files with 48 additions and 0 deletions.

x
0 of 2 viewed, 2 left
24 additions and 0 deletionsdocs/start/framework/react/guide/routing.mdModified
View file
@@ -202,6 +202,30 @@
| `/posts/:postId` | `posts/$postId.tsx` | Dynamic Route |
| `/rest/*` | `rest/$.tsx` | Wildcard Route |
​
+When the route generator creates a file such as `posts.tsx`, it adds a starter
+component. Because `posts.tsx` is the parent of `posts/index.tsx` and
+`posts/$postId.tsx`, its component must render an `<Outlet />` for those child
+routes to appear:
+​
+```tsx title="src/routes/posts.tsx"
+import { Outlet, createFileRoute } from '@tanstack/react-router'
+​
+export const Route = createFileRoute('/posts')({
+ component: PostsLayout,
+})
+​
+function PostsLayout() {
+ return <Outlet />
+}
+```
+​
+Place `<Outlet />` wherever the child route should render within any shared
+layout UI. If the parent route does not need a component, remove the generated
+`component` option instead; a route without a component renders an outlet
+automatically by default. If the router has a `defaultComponent`, the route
+renders that component instead, so it must render an `<Outlet />` for child