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/API.md
+4-55Lines changed: 4 additions & 55 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,7 @@
4
4
-[`<Router>`](#router)
5
5
-[`<Link>`](#link)
6
6
-[`<IndexLink>`](#indexlink)
7
+
-[`withRouter`](#withRouter-component)
7
8
-[`<RouterContext>`](#routercontext)
8
9
-[`context.router`](#contextrouter)
9
10
-`<RoutingContext>` (deprecated, use `<RouterContext>`)
@@ -162,6 +163,9 @@ Given a route like `<Route path="/users/:userId" />`:
162
163
### `<IndexLink>`
163
164
An `<IndexLink>` is like a [`<Link>`](#link), except it is only active when the current route is exactly the linked route. It is equivalent to `<Link>` with the `onlyActiveOnIndex` prop set.
164
165
166
+
### `withRouter(component)`
167
+
A HoC (higher-order component) that wraps another component to provide `this.props.router`. Pass in your component and it will return the wrapped component.
168
+
165
169
### `<RouterContext>`
166
170
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
171
@@ -171,61 +175,6 @@ It also provides a `router` object on [context](https://facebook.github.io/react
171
175
172
176
Contains data and methods relevant to routing. Most useful for imperatively transitioning around the application.
173
177
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
-
229
178
##### `push(pathOrLoc)`
230
179
Transitions to a new URL, adding a new entry in the browser history.
Copy file name to clipboardExpand all lines: docs/guides/NavigatingOutsideOfComponents.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Navigating Outside of Components
2
2
3
-
While you can use `this.context.router` to navigate around, many apps want to be able to navigate outside of their components. They can do that with the history the app gives to `Router`.
3
+
While you can use `this.props.router` from `withRouter` to navigate around, many apps want to be able to navigate outside of their components. They can do that with the history the app gives to `Router`.
0 commit comments