Skip to content

Commit 7355a18

Browse files
committed
upgrade guide
1 parent de1685e commit 7355a18

File tree

3 files changed

+218
-7
lines changed

3 files changed

+218
-7
lines changed

UPGRADE_GUIDE.md

Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,219 @@ To see discussion around these API changes, please refer to the
55
[changelog](/CHANGELOG.md) and visit the commits and issues they
66
reference.
77

8+
0.10.x -> 0.11.x
9+
----------------
10+
11+
The router changed **a lot** in this release. While you won't have to
12+
change too much of your app, you will have to change it in a lot of
13+
places. The fundamental change is that you, rather than the router, get
14+
to have control of your view instances.
15+
16+
If you find anything is missing from this list, please open an issue and
17+
we will get it added here ASAP.
18+
19+
### React 0.12
20+
21+
You must upgrade to `0.12.x` before you can use version `0.11.x` of the
22+
router.
23+
24+
### `<Routes/>` and starting the router
25+
26+
`<Routes/>` is gone, there is a new API that gives you complete control
27+
of your views.
28+
29+
```js
30+
// 0.10.x
31+
React.render(routes, el);
32+
33+
// 0.11.x
34+
Router.run(routes, function (Handler) {
35+
React.render(<Handler/>, el);
36+
});
37+
38+
// or if using history location
39+
Router.run(routes, Router.HistoryLocation, function (Handler) {
40+
React.render(<Handler/>, el);
41+
});
42+
```
43+
44+
### `this.props.activeRouteHandler()` -> `<RouteHandler/>`
45+
46+
```js
47+
// 0.10.x
48+
var Something = React.createClass({
49+
render: function () {
50+
return (
51+
<div>
52+
<this.props.activeRouteHandler />
53+
</div>
54+
);
55+
}
56+
});
57+
58+
// 0.11.x
59+
var RouteHandler = Router.RouteHandler;
60+
61+
var Something = React.createClass({
62+
render: function () {
63+
return (
64+
<div>
65+
<RouteHandler />
66+
</div>
67+
);
68+
}
69+
});
70+
```
71+
72+
### `this.props.params` and `this.props.query`
73+
74+
They are no longer available on props, use the `State` mixin.
75+
76+
```js
77+
// 0.10.x
78+
var Something = React.createClass({
79+
render: function () {
80+
var name = this.props.params.name;
81+
var something = this.props.query.something;
82+
// ...
83+
}
84+
});
85+
86+
// 0.11.x
87+
var Something = React.createClass({
88+
mixins: [ Router.State ],
89+
render: function () {
90+
var name = this.getParams().name;
91+
var something = this.getQuery().something;
92+
// ...
93+
}
94+
});
95+
96+
// or pass it down the view hierarchy
97+
Router.run(routes, function (Handler, state) {
98+
React.render(<Handler params={state.params} query={state.query} />, el);
99+
// make sure to `<RouteHandler {...this.props}/>` to continue
100+
// passing it down the hierarchy
101+
});
102+
```
103+
104+
### `ActiveState` -> `State`, and methods too
105+
106+
This mixin's name has changed, and all of its methods that had the word
107+
`active` in it, too. For example, `getActiveParams()` becomes `getParams()`.
108+
109+
```js
110+
// v0.10.x
111+
var Something = React.createClass({
112+
mixins: [ Router.ActiveState ],
113+
render: function () {
114+
var name = this.getActiveParams().name;
115+
// ...
116+
}
117+
});
118+
119+
// v0.11.x
120+
var Something = React.createClass({
121+
mixins: [ Router.State ]
122+
render: function () {
123+
var name = this.getParams().name;
124+
// ...
125+
}
126+
});
127+
```
128+
129+
### `CurrentPath` -> `State`
130+
131+
You can find `this.getPath()` on the `Router.State` mixin.
132+
133+
```js
134+
// v0.10.x
135+
var Something = React.createClass({
136+
mixins: [ Router.CurrentPath ],
137+
render: function () {
138+
var path = this.getCurrentPath();
139+
// ...
140+
}
141+
});
142+
143+
// v0.11.x
144+
var Something = React.createClass({
145+
mixins: [ Router.State ],
146+
render: function () {
147+
var path = this.getPath();
148+
// ...
149+
}
150+
});
151+
```
152+
153+
### Route `addHandlerKey` prop
154+
155+
This option has been removed, you will need to add handler keys
156+
yourself:
157+
158+
```js
159+
// 0.10.x
160+
<Route handler={App}>
161+
<Route addHandlerKey={true}/>
162+
</Route>
163+
164+
// 0.11.x
165+
var App = React.createClass({
166+
mixins: [ Router.State ],
167+
render: function () {
168+
var key = this.getPath();
169+
return (
170+
<div>
171+
<RouteHandler key={key} />
172+
</div>
173+
);
174+
}
175+
});
176+
```
177+
178+
### `<Routes onError={fn}/>`
179+
180+
`<Routes/>` is gone, instead create a router with your error handler as
181+
an option:
182+
183+
```js
184+
// 0.10.x
185+
<Routes onError={fn}>
186+
// ...
187+
</Routes>
188+
189+
// 0.11.x
190+
var router = Router.create({
191+
onErorr: fn,
192+
// ...
193+
});
194+
router.run(callback);
195+
```
196+
197+
### `Router.renderRoutesTo*`
198+
199+
These methods have been removed because you, not the router, are in
200+
control of rendering.
201+
202+
```js
203+
// v0.10.x
204+
Router.renderRoutesToString(routes, path, function(html) {
205+
// do something with `html`
206+
});
207+
208+
// v0.11.x
209+
Router.run(routes, path, function(Handler) {
210+
var html = React.renderToString(<Handler/>);
211+
});
212+
```
213+
214+
0.9.x -> 0.10.x
215+
---------------
216+
217+
Nothing changed, this was simply React `0.12.0` compatibility. Note,
218+
your code needs to use the React `0.11.x` API for things to work, there
219+
will be lots of warnings in the console.
220+
8221
0.7.x -> 0.9.x
9222
--------------
10223

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
"react": "0.12.x"
4646
},
4747
"dependencies": {
48-
"events": "1.0.1",
4948
"qs": "2.2.2",
5049
"when": "3.4.6"
5150
},

tests.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
require('./modules/__tests__/Router-test');
22

3-
require('./modules/elements/__tests__/DefaultRoute-test');
4-
require('./modules/elements/__tests__/Link-test');
5-
require('./modules/elements/__tests__/NotFoundRoute-test');
6-
require('./modules/elements/__tests__/Redirect-test');
7-
require('./modules/elements/__tests__/RouteHandler-test');
8-
// require('./modules/elements/__tests__/Routes-test');
3+
require('./modules/components/__tests__/DefaultRoute-test');
4+
require('./modules/components/__tests__/Link-test');
5+
require('./modules/components/__tests__/NotFoundRoute-test');
6+
require('./modules/components/__tests__/Redirect-test');
7+
require('./modules/components/__tests__/RouteHandler-test');
98

109
require('./modules/mixins/__tests__/State-test');
1110

0 commit comments

Comments
 (0)