git ssb

7+

dinoworm 🐛 / patchcore



Commit b1e166bd62bc7ba5a3aa02c55e004a0e4c1cafea

write more complete docs for router

mix irving committed on 8/7/2017, 11:13:02 AM
Parent: 7c9aac9f7f081e157970a4e5392c460bad944f2e

Files changed

docs/router.mdchanged
docs/router.mdView
@@ -1,17 +1,36 @@
11 # Router
22
33 ## Adding routes
44
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:
66
77 ```
88 [ routeValidator, routeFunction ]
99 ```
1010
1111 Where `routeValidator` is a function that returns true / false when given a `location` object.
1212
13 +Here's a simple example of extending the routes
1314
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 +
1433 ## Using the router
1534
1635 The router is accessible at `app.sync.router`, and can be used like :
1736

Built with git-ssb-web