Skip to content

Commit 784bd04

Browse files
authored
docs: Expound upon nested routing example, explain matching (#91)
1 parent 7b4ad1f commit 784bd04

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,22 @@ export async function prerender(data) {
7474

7575
## Nested Routing
7676

77-
Nested routes are supported by using multiple `Router` components. Partially matched routes end with a wildcard (`/*`) and the remaining value will be passed to continue matching with if there are any further routes.
77+
Some applications would benefit from having routers of multiple levels, allowing to break down the routing logic into smaller components. This is especially useful for larger applications, and we solve this by allowing for multiple nested `<Router>` components.
78+
79+
Partially matched routes end with a wildcard (`/*`) and only the remaining value will be passed to descendant routers for further matching. This allows you to create a parent route that matches a base path, and then have child routes that match specific sub-paths.
7880

7981
```js
8082
import { lazy, LocationProvider, ErrorBoundary, Router, Route } from 'preact-iso';
8183

84+
import AllMovies from './routes/movies/all.js';
85+
8286
const NotFound = lazy(() => import('./routes/_404.js'));
8387

8488
const App = () => (
8589
<LocationProvider>
8690
<ErrorBoundary>
8791
<Router>
92+
<Router path="/movies" component={AllMovies} />
8893
<Route path="/movies/*" component={Movies} />
8994
<NotFound default />
9095
</Router>
@@ -107,10 +112,15 @@ const Movies = () => (
107112
);
108113
```
109114

110-
This will match the following routes:
115+
The `<Movies>` component will be used for the following routes:
111116
- `/movies/trending`
112117
- `/movies/search`
113118
- `/movies/Inception`
119+
- `/movies/...`
120+
121+
It will not be used for any of the following:
122+
- `/movies`
123+
- `/movies/`
114124

115125
---
116126

0 commit comments

Comments
 (0)