You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/route.md
+44Lines changed: 44 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,10 @@
2
2
3
3
Routing components allow you to create implement single page app routing functionality.
4
4
5
+
- Provides *dynamic* routing, [just like `react-router`](https://reacttraining.com/react-router/core/guides/philosophy/dynamic-routing)
6
+
- Use any state container
7
+
- Multiple routers on one page
8
+
5
9
Contents:
6
10
7
11
-[`<Router>`](#router)
@@ -10,6 +14,46 @@ Contents:
10
14
-[`withRoute()`](#withroute)
11
15
12
16
17
+
## Use any state container
18
+
19
+
With libreact's `<Router>` you can choose to store the current route in your state continer (like Redux or MobX) of
20
+
choice, or not bother about it at all, in which case the `<Router>` will just use the current browser location out-of-the box.
21
+
22
+
The "problem-of-routers" is that they all want to be the ones that keep the state of the route. For example, [`react-router`](https://reacttraining.com/react-router/) uses
23
+
its internal history objects to store route information, and [it does not give you good access to that data structure](http://formidable.com/blog/2016/07/11/let-the-url-do-the-talking-part-1-the-pain-of-react-router-in-redux/).
24
+
25
+
So, if you wanted to store the state of the route in Redux, there was no good way for you to do that using `react-router`, that is why
26
+
[`redux-little-router`](https://github.com/FormidableLabs/redux-little-router) was born, however, `redux-little-router` itself hoards the
27
+
state of the route in Redux, so you cannot use it if you use any other state container, say MobX.
28
+
29
+
Libreact is completely orthogonal to where you store the current route, all you have to do is provide the current route to the `<Router>` component:
30
+
31
+
```jsx
32
+
<Router route={currentRoute}>
33
+
{/* ... */}
34
+
</Router>
35
+
```
36
+
37
+
You can story in Redux or MobX, or really anywhere you want. And if you don't want to bother, don't! Just use the current location of the browser:
38
+
39
+
```jsx
40
+
<LocationSensor>{({pathname}) =>
41
+
<Router route={pathname}>
42
+
{/* ... */}
43
+
</Router>
44
+
}</LocationSensor>
45
+
```
46
+
47
+
Actually, you don't even have to do that, if you don't explicitly specify the `route` prop, the `<Router>` component will do exactly that for you under the hood,
48
+
so, simply use:
49
+
50
+
```jsx
51
+
<Router>
52
+
{/* ... */}
53
+
</Router>
54
+
```
55
+
56
+
13
57
## `<Router>`
14
58
15
59
`Router` is a root component that provides routing to your application. I should be placed above all other components
0 commit comments