Skip to content

Commit 7a79fcd

Browse files
committed
chore(docs): added new faq
1 parent 35a7ff0 commit 7a79fcd

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

docs/faq.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,67 @@ function MatchPath({ path, Comp }) {
194194
<MatchPath path="/accounts/:id" Comp={Account} />;
195195
```
196196

197+
## How do I nest routes deep in the tree?
198+
199+
In v5 you could render a `<Route>` or `<Switch>` anywhere you want. You can keep doing the very same thing but you need to use `<Routes>` (`<Route>` without an 's' will not work). We call these "Descendant `<Routes>`".
200+
201+
It might have looked like this in v5
202+
203+
```tsx filename=v5.js
204+
// somewhere up the tree
205+
<Switch>
206+
<Route path="/users" component={Users} />
207+
</Switch>
208+
209+
// and now deeper in the tree
210+
function Users() {
211+
return (
212+
<div>
213+
<h1>Users</h1>
214+
<Switch>
215+
<Route path="/users/accont" component={Account} />
216+
</Switch>
217+
</div>
218+
)
219+
}
220+
```
221+
222+
In v6 it's almost the same:
223+
224+
- Note the `*` in the ancestor routes to get it to match deeper URLs even though it has no direct children
225+
- You no longer need to know the entire child route path, you can use a relative route now
226+
227+
```tsx filename=v6.js
228+
// somewhere up the tree
229+
<Routes>
230+
<Route path="/users/*" element={<Users />} />
231+
</Routes>
232+
233+
// and now deeper in the tree
234+
function Users() {
235+
return (
236+
<div>
237+
<h1>Users</h1>
238+
<Routes>
239+
<Route path="account" element={<Account />} />
240+
</Routes>
241+
</div>
242+
)
243+
}
244+
```
245+
246+
If you had a "floating route" in v5 (not wrapped in a `<Switch>`), simply wrap it in a `<Routes>` instead.
247+
248+
```tsx
249+
// v5
250+
<Route path="/contact" component={Contact} />
251+
252+
// v6
253+
<Routes>
254+
<Route path="contact" element={<Contact />} />
255+
</Routes>
256+
```
257+
197258
## What Happened to Regexp Routes Paths?
198259

199260
Regexp route paths were removed for two reasons:
@@ -359,3 +420,5 @@ function User() {
359420
```
360421

361422
Instead of rending your component, remix will render the nearest [catch boundary](https://docs.remix.run/v0.20/api/app/#catchboundary) instead.
423+
424+

0 commit comments

Comments
 (0)