Skip to content

Commit b8ffde5

Browse files
committed
docs: overview tweaks
1 parent 30b6458 commit b8ffde5

File tree

1 file changed

+59
-20
lines changed

1 file changed

+59
-20
lines changed

docs/start/overview.md

Lines changed: 59 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -58,26 +58,65 @@ Nested Routing is the general idea of coupling segments of the URL to component
5858
React Router embraces this convention with APIs for creating nested layouts coupled to URL segments and data.
5959

6060
```jsx
61-
<Route path="/" element={<Root />}>
62-
<Route path="contact" element={<Contact />} />
63-
<Route
64-
path="dashboard"
65-
element={<Dashboard />}
66-
loader={({ request }) =>
67-
fetch("/api/dashboard.json", {
68-
signal: request.signal,
69-
})
70-
}
71-
/>
72-
<Route element={<AuthLayout />}>
73-
<Route
74-
path="login"
75-
element={<Login />}
76-
loader={redirectIfUser}
77-
/>
78-
<Route path="logout" />
79-
</Route>
80-
</Route>
61+
// Configure nested routes with JSX
62+
createBrowserRouter(
63+
createRoutesFromElements(
64+
<Route path="/" element={<Root />}>
65+
<Route path="contact" element={<Contact />} />
66+
<Route
67+
path="dashboard"
68+
element={<Dashboard />}
69+
loader={fetch("/api/dashboard.json", {
70+
signal: request.signal,
71+
})}
72+
/>
73+
<Route element={<AuthLayout />}>
74+
<Route
75+
path="login"
76+
element={<Login />}
77+
loader={redirectIfUser}
78+
/>
79+
<Route path="logout" />
80+
</Route>
81+
</Route>
82+
)
83+
);
84+
85+
// Or use plain objects
86+
createBrowserRouter([
87+
{
88+
path: "/",
89+
element: <Root />,
90+
children: [
91+
{
92+
path: "contact",
93+
element: <Contact />,
94+
},
95+
{
96+
path: "dashboard",
97+
element: <Dashboard />,
98+
loader: ({ request }) =>
99+
fetch("/api/dashboard.json", {
100+
signal: request.signal,
101+
}),
102+
},
103+
{
104+
element: <AuthLayout />,
105+
children: [
106+
{
107+
path: "login",
108+
element: <Login />,
109+
loader: redirectIfUser,
110+
},
111+
{
112+
path: "logout",
113+
action: logoutUser,
114+
},
115+
],
116+
},
117+
],
118+
},
119+
]);
81120
```
82121

83122
This [visualization](https://remix.run/_docs/routing) might be helpful.

0 commit comments

Comments
 (0)