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
+27-14Lines changed: 27 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,12 @@
1
1
# Route
2
2
3
-
Routing components allow you to create implement single page app routing functionality.
3
+
Routing components that allow you to 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
5
+
-Provide*dynamic* routing, [just like `react-router`](https://reacttraining.com/react-router/core/guides/philosophy/dynamic-routing)
6
+
- Use [any state container](#use-any-state-container)
7
+
-[Multiple routers](#multiple-routers) on one page
8
8
9
-
Contents:
9
+
Reference:
10
10
11
11
-[`<Router>`](#router)
12
12
-[`<Route>`](#route)
@@ -17,24 +17,25 @@ Contents:
17
17
## Use any state container
18
18
19
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-thebox.
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
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
22
+
The "problem-of-all-routers" is that they all want to keep the state of the route. For example, [`react-router`](https://reacttraining.com/react-router/) uses
23
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
24
25
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
26
[`redux-little-router`](https://github.com/FormidableLabs/redux-little-router) was born, however, `redux-little-router` itself hoards the
27
27
state of the route in Redux, so you cannot use it if you use any other state container, say MobX.
28
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:
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>`
30
+
coponent using the `route` prop.
30
31
31
32
```jsx
32
33
<Router route={currentRoute}>
33
34
{/* ... */}
34
35
</Router>
35
36
```
36
37
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
+
You can store it 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
39
40
```jsx
40
41
<LocationSensor>{({pathname}) =>
@@ -44,7 +45,7 @@ You can story in Redux or MobX, or really anywhere you want. And if you don't wa
44
45
}</LocationSensor>
45
46
```
46
47
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 underthehood,
48
+
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
49
so, simply use:
49
50
50
51
```jsx
@@ -54,13 +55,25 @@ so, simply use:
54
55
```
55
56
56
57
57
-
## `<Router>`
58
+
## Multiple routers
59
+
60
+
You can have many routers operating on the same page in parallel. All you have to do is specify a *namespace* using the `ns` props.
61
+
62
+
```jsx
63
+
<Router ns='secret'>
64
+
<Route ns='secret'/>
65
+
</Router>
66
+
```
67
+
68
+
## Reference
69
+
70
+
### `<Router>`
58
71
59
72
`Router` is a root component that provides routing to your application. I should be placed above all other components
60
73
that use routing. It uses React's context [`Provider`](./context.md#provider) component to provide route information to
61
74
its children.
62
75
63
-
### Props
76
+
####Props
64
77
65
78
-`route` - optional, string, route to use for routing. If not specified, `<Router>` will use
66
79
[`<LocationSensor>`](./LocationSensor.md) internally to track any changes to `window.location`.
@@ -71,13 +84,13 @@ Unlike other routing libraries `<Router>` component lets you specify the current
71
84
this way you can use Redux or MobX, or any other state container library to store your route, if you want to.
72
85
73
86
74
-
## `<Route>`
87
+
###`<Route>`
75
88
76
89
`Route` tries to match a fragment in a route. If it does match, the contents of the route is rendered. The contents of the route
77
90
can be either regular JSX children or a FaCC or a React component specified in the `comp` prop.
78
91
79
92
80
-
### Props
93
+
####Props
81
94
82
95
-`match`, optional, matching condition, defaults to `/.+/`, see discussion below.
0 commit comments