@@ -5,9 +5,228 @@ To see discussion around these API changes, please refer to the
5
5
[ changelog] ( /CHANGELOG.md ) and visit the commits and issues they
6
6
reference.
7
7
8
- 0.13.3 -> 1.0.0-rc1
9
- -------------------
10
- Todo
8
+ 0.13.3 -> 1.0.0
9
+ ---------------
10
+
11
+ Thanks for your patience :) Big changes.
12
+
13
+ ### Rendering
14
+
15
+ ``` js
16
+ // v0.13.x
17
+ Router .run (routes, (Handler ) => {
18
+ React .render (< Handler/ > , el);
19
+ })
20
+
21
+ // v1.0
22
+ React .render (< Router> {routes}< / Router> , el)
23
+
24
+ // looks more like this:
25
+ React .render ((
26
+ < Router>
27
+ < Route path= " /" component= {App}/ >
28
+ < / Router>
29
+ ), el);
30
+
31
+ // or if you'd rather
32
+ React .render (< Router routes= {routes}/ > , el)
33
+ ```
34
+
35
+ ### Route Config
36
+
37
+ You can still nest your routes as before, paths are inherited from
38
+ parents just like before but prop names have changed.
39
+
40
+ ``` js
41
+ // v0.13.x
42
+ < Route name= " about" handler= {About}/ >
43
+
44
+ // v1.0
45
+ < Route path= " about" component= {About}/ >
46
+ ```
47
+
48
+ Named routes are gone, see discussion [ here] ( https://github.com/rackt/react-router/issues/1840 )
49
+
50
+ ### NotFound route
51
+
52
+ Not found really confused people mistaking it for not finding resources
53
+ from your API for not matching a route. We've removed it completely
54
+ since its simple with a ` * ` path.
55
+
56
+ ``` js
57
+ // v0.13.x
58
+ < NotFoundRoute handler= {NoMatch}/ >
59
+
60
+ // v1.0
61
+ < Route path= " *" / >
62
+ ```
63
+
64
+ ### Redirect route
65
+
66
+ - no more params
67
+ - must have absolute "from" (for now)
68
+
69
+ ``` js
70
+ // v0.13.x
71
+ < Redirect from= " some/where/:id" to= " somewhere/else/:id" params= {{id: 2 }}/ >
72
+
73
+ // v1.0
74
+ // Works the same as before, except no params, just put them in the path
75
+ < Redirect from= " /some/where/:id" to= " /somewhere/else/2" / >
76
+ ```
77
+
78
+ ### Links
79
+
80
+ #### path / params
81
+
82
+ ``` js
83
+ // v0.13.x
84
+ < Link to= " user" params= {{userId: user .id }}> Mateusz< / Link>
85
+
86
+ // v1.0
87
+ // because named routes are gone, link to full paths, you no longer need
88
+ // to know the names of the parameters, and string templates are quite
89
+ // nice. Note that `query` has not changed.
90
+ < Link to= {` /users/${ user .id } ` }> Mateusz< / Link>
91
+ ```
92
+
93
+ #### "active" class
94
+
95
+ In 0.13.x links added the "active" class by default which you could
96
+ override with ` activeClassName ` , or provide ` activeStyles ` . Most links
97
+ don't need this and the check is (currently) expensive.
98
+
99
+ Links no longer add the "active" class by default, you opt-in by
100
+ providing one; if no ` activeClassName ` or ` activeStyles ` are provided,
101
+ the link will not check if its active.
102
+
103
+ ``` js
104
+ // v0.13.x
105
+ < Link to= " about" > About< / Link>
106
+
107
+ // v1.0
108
+ < Link to= " /about" activeClassName= " active" > About< / Link>
109
+ ```
110
+
111
+ #### Linking to Defult/Index routes
112
+
113
+ Because named routes are gone, a link to ` / ` with an index route at ` / `
114
+ will always be active. So we've introduced ` IndexLink ` that is only
115
+ active when the index route is active.
116
+
117
+ ``` js
118
+ // v0.13.x
119
+ // with this route config
120
+ < Route path= " /" handler= {App}>
121
+ < DefaultRoute name= " home" handler= {Home}/ >
122
+ < Route name= " about" handler= {About}/ >
123
+ < / Route>
124
+
125
+ // will be active only when home is active, not when about is active
126
+ < Link to= " home" > Home< / Link>
127
+
128
+ // v1.0
129
+ < Route path= " /" component= {App}>
130
+ < IndexRoute handler= {Home}/ >
131
+ < Route path= " about" handler= {About}/ >
132
+ < / Route>
133
+
134
+ // will be active only when home is active, not when about is active
135
+ < IndexLink to= " /" > Home< / Link>
136
+ ```
137
+
138
+ ### Navigation Mixin
139
+
140
+ If you were using the navigation, instead use the ` History ` mixin.
141
+
142
+ ``` js
143
+ // v0.13.x
144
+ var Assignment = React .createClass ({
145
+ mixins: [ Navigation ],
146
+ navigateAfterSomethingHappened () {
147
+ this .transitionTo (' /users' , { userId: user .id }, query);
148
+ // this.replaceWith('/users', { userId: user.id }, query);
149
+ }
150
+ })
151
+
152
+ // v1.0
153
+ var Assignment = React .createClass ({
154
+ mixins: [ History ],
155
+ navigateAfterSomethingHappened () {
156
+ // the router is not built on rackt/history, and it is a first class
157
+ // API in the router for navigating
158
+ this .history .pushState (null , ` /users/${ user .id } ` , query);
159
+ // this.history.replaceState(null, `/users/${user.id}`, query);
160
+ }
161
+ })
162
+ ```
163
+
164
+ The following ` Navigation ` methods are now also found on the history
165
+ object, main difference again is there are no params or route names,
166
+ just pathnames.
167
+
168
+ | v0.13 | v1.0 |
169
+ | --------------------------------------| -------------------------------|
170
+ | ` go(n) ` | ` go(n) ` |
171
+ | ` goBack() ` | ` goBack() ` |
172
+ | ` goForward() ` | ` goForward() ` |
173
+ | ` makeHref(routeName, params, query) ` | ` createHref(pathname, query) ` |
174
+ | ` makePath(routeName, params, query) ` | ` createPath(pathname, query) ` |
175
+
176
+ ### State mixin
177
+
178
+ ``` js
179
+ // v0.13.x
180
+ var Assignment = React .createClass ({
181
+ mixins: [ State ],
182
+ foo () {
183
+ this .getPath ()
184
+ this .getParams ()
185
+ // etc...
186
+ }
187
+ })
188
+
189
+ // v1.0
190
+ // if you are a route component...
191
+ < Route component= {Assignment/ >
192
+
193
+ var Assignment = React .createClass ({
194
+ foo () {
195
+ this .props .location // contains path information
196
+ this .props .params // contains params
197
+ this .props .history .isActive
198
+ }
199
+ })
200
+
201
+ // if you're not a route component, you need to pass location down the
202
+ // tree or get the location from context, we will probably provide a
203
+ // higher order component that will do this for you but haven't yet
204
+ var Assignment = React .createClass ({
205
+ contextTypes: {
206
+ location: React .PropTypes .object
207
+ },
208
+ foo () {
209
+ this .context .location
210
+ }
211
+ })
212
+ ` ` `
213
+
214
+ Here's a table of where you used to get stuff with the ` State` mixin,
215
+ and where you get it now if you're a route component (` this .props ` )
216
+
217
+
218
+ | v0.13 (this) | v1.0 (this.props) |
219
+ |-----------------|------------------------------------|
220
+ | ` getPath ()` | ` location .pathname + location .query ` |
221
+ | ` getPathname ()` | ` location .pathname ` |
222
+ | ` getParams ()` | ` params` |
223
+ | ` getQuery ()` | ` query` |
224
+ | ` getRoutes ()` | ` routes` |
225
+
226
+ ### We'll keep updating this
227
+
228
+ There's a lot of the old API we've missed, please give the [new
229
+ docs][/docs] a read and help us fill this guide in. Thansk!
11
230
12
231
13
232
0.13.2 -> 0.13.3
0 commit comments