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
-**Feature:** Add `applyRouterMiddleware` for extending router rendering ([#3327])
5
+
-**Feature/Deprecation:** Add `routerShape` and `locationShape` as top-level exported prop types, and deprecate all the old prop types, including the ones that were previously incorrectly removed ([#3349])
6
+
-**Minor:** Move ES module build back to `es6/` to avoid breaking people who were incorrectly importing from `react-router/es6` ([#3334])
Copy file name to clipboardExpand all lines: docs/API.md
+61-9Lines changed: 61 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -165,12 +165,67 @@ An `<IndexLink>` is like a [`<Link>`](#link), except it is only active when the
165
165
### `<RouterContext>`
166
166
A `<RouterContext>` renders the component tree for a given router state. Its used by `<Router>` but also useful for server rendering and integrating in brownfield development.
167
167
168
-
It also provides a `router` object on `context`.
168
+
It also provides a `router` object on [context](https://facebook.github.io/react/docs/context.html).
169
169
170
170
#### `context.router`
171
171
172
172
Contains data and methods relevant to routing. Most useful for imperatively transitioning around the application.
173
173
174
+
To use it, you must signal to React that you need it by declaring your use of it in your component via `contextTypes`:
175
+
176
+
```js
177
+
var MyComponent =React.createClass({
178
+
contextTypes: {
179
+
router:routerShape.isRequired
180
+
},
181
+
182
+
render:function() {
183
+
// Here, you can use this.context.router.
184
+
}
185
+
})
186
+
```
187
+
188
+
To use `context.router` on a component declared as an ES2015 class, define `contextTypes` as a static property of the class:
189
+
190
+
```js
191
+
classMyComponentextendsReact.Component {
192
+
render() {
193
+
// Here, you can use this.context.router.
194
+
}
195
+
}
196
+
197
+
MyComponent.contextTypes= {
198
+
router:routerShape.isRequired
199
+
}
200
+
```
201
+
202
+
If you are using the class properties proposal, you can instead write:
203
+
204
+
```js
205
+
classMyComponentextendsReact.Component {
206
+
static contextTypes = {
207
+
router:routerShape.isRequired
208
+
}
209
+
210
+
render() {
211
+
// Here, you can use this.context.router.
212
+
}
213
+
}
214
+
```
215
+
216
+
To use `context.router` with
217
+
[stateless function components](https://facebook.github.io/react/docs/reusable-components.html#stateless-functions), declare `contextTypes` as a static property of the component function:
218
+
219
+
```js
220
+
functionMyComponent(props, context) {
221
+
// Here, you can use context.router.
222
+
}
223
+
224
+
MyComponent.contextTypes= {
225
+
router:routerShape.isRequired
226
+
}
227
+
```
228
+
174
229
##### `push(pathOrLoc)`
175
230
Transitions to a new URL, adding a new entry in the browser history.
176
231
@@ -639,14 +694,11 @@ One or many [`<Route>`](#route)s or [`PlainRoute`](#plainroute)s.
639
694
640
695
641
696
### `PropTypes`
642
-
The following objects are exposed as properties of the exported PropTypes object:
643
-
-`falsy`: Checks that a component does not have a prop
644
-
-`history`
645
-
-`location`
646
-
-`component`
647
-
-`components`
648
-
-`route`
649
-
-`routes`
697
+
The following prop types are exported at top level and from `react-router/lib/PropTypes`:
698
+
-`routerShape`: Shape for the `router` object on context
699
+
-`locationShape`: Shape for the `location` object on route component props
700
+
701
+
Previously, a number of prop types intended for internal use were also exported under `PropTypes`. These are deprecated and should not be used.
Copy file name to clipboardExpand all lines: docs/Glossary.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -231,6 +231,7 @@ A *route pattern* (or "path") is a string that describes a portion of a URL. Pat
231
231
- `:paramName` – matches a URL segment up to the next `/`, `?`, or `#`. The matched string is called a [param](#params)
232
232
- `()` – Wraps a portion of the URL that is optional
233
233
- `*` – Matches all characters (non-greedy) up to the next character in the pattern, or to the end of the URL if there is none, and creates a `splat` [param](#params)
234
+
- `**` - Matches all characters (greedy) until the next `/`, `?`, or `#` and creates a `splat` [param](#params)
234
235
235
236
Route patterns are relative to the pattern of the parent route unless they begin with a `/`, in which case they begin matching at the beginning of the URL.
0 commit comments