Commit b1e166bd62bc7ba5a3aa02c55e004a0e4c1cafea
write more complete docs for router
mix irving committed on 8/7/2017, 11:13:02 AMParent: 7c9aac9f7f081e157970a4e5392c460bad944f2e
Files changed
docs/router.md | changed |
docs/router.md | ||
---|---|---|
@@ -1,17 +1,36 @@ | ||
1 | 1 … | # Router |
2 | 2 … | |
3 | 3 … | ## Adding routes |
4 | 4 … | |
5 | -Patchcore collects _routes_ from `router.sync.routes`. It expects arrays of the form: | |
5 … | +Patchcore collects _routes_ from `router.sync.routes` as a reduce. It expects the final routes collection to be an array of arrays of the form: | |
6 | 6 … | |
7 | 7 … | ``` |
8 | 8 … | [ routeValidator, routeFunction ] |
9 | 9 … | ``` |
10 | 10 … | |
11 | 11 … | Where `routeValidator` is a function that returns true / false when given a `location` object. |
12 | 12 … | |
13 … | +Here's a simple example of extending the routes | |
13 | 14 … | |
15 … | +```js | |
16 … | +exports.create = (api) => { | |
17 … | + return { router: { sync: { routes } } } | |
18 … | + | |
19 … | + function routes (sofar = []) { | |
20 … | + const moreRoutes = [ | |
21 … | + [ (location) => location.page === 'home', api.app.page.home ], | |
22 … | + [ (location) => location.type === 'group', api.app.page.group ], | |
23 … | + [ () => true, api.app.page.notFound ] | |
24 … | + ] | |
25 … | + | |
26 … | + return [...moreRoutes, ...sofar] | |
27 … | + // Note order matters here | |
28 … | + } | |
29 … | +} | |
30 … | +``` | |
31 … | + | |
32 … | + | |
14 | 33 … | ## Using the router |
15 | 34 … | |
16 | 35 … | The router is accessible at `app.sync.router`, and can be used like : |
17 | 36 … |
Built with git-ssb-web