Skip to content

Commit b3c37a8

Browse files
committed
Merge remote-tracking branch 'origin/master' into next
2 parents 1a73278 + 70c23b4 commit b3c37a8

File tree

28 files changed

+264
-127
lines changed

28 files changed

+264
-127
lines changed

.babelrc

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
{
2-
"stage": 0,
3-
"loose": "all",
4-
"plugins": [
5-
"dev-expression"
6-
]
2+
"presets": ["stage-0", "react"],
3+
"plugins": ["dev-expression"],
4+
5+
"env": {
6+
"cjs": {
7+
"presets": ["es2015-loose"],
8+
"plugins": ["add-module-exports"]
9+
},
10+
"es": {
11+
"presets": ["es2015-loose-native-modules"]
12+
}
13+
}
714
}

CHANGES.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
## [HEAD]
2-
> Unreleased
1+
## [v2.3.0]
2+
> April 18, 2016
33
4-
- **Feature:** Added `applyRouterMiddleware` ([#3327])
4+
- **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])
57

6-
[HEAD]: https://github.com/reactjs/react-router/compare/v2.2.4...master
8+
[v2.3.0]: https://github.com/reactjs/react-router/compare/v2.2.4...v2.3.0
79
[#3327]: https://github.com/reactjs/react-router/issues/3327
10+
[#3334]: https://github.com/reactjs/react-router/issues/3334
11+
[#3349]: https://github.com/reactjs/react-router/issues/3349
12+
813

914
## [v2.2.4]
1015
> April 15, 2016

docs/API.md

Lines changed: 61 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,67 @@ An `<IndexLink>` is like a [`<Link>`](#link), except it is only active when the
165165
### `<RouterContext>`
166166
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.
167167

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).
169169

170170
#### `context.router`
171171

172172
Contains data and methods relevant to routing. Most useful for imperatively transitioning around the application.
173173

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+
class MyComponent extends React.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+
class MyComponent extends React.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+
function MyComponent(props, context) {
221+
// Here, you can use context.router.
222+
}
223+
224+
MyComponent.contextTypes = {
225+
router: routerShape.isRequired
226+
}
227+
```
228+
174229
##### `push(pathOrLoc)`
175230
Transitions to a new URL, adding a new entry in the browser history.
176231

@@ -639,14 +694,11 @@ One or many [`<Route>`](#route)s or [`PlainRoute`](#plainroute)s.
639694

640695

641696
### `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.
650702

651703

652704
### `useRoutes(createHistory)` (deprecated)

docs/Glossary.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ A *route pattern* (or "path") is a string that describes a portion of a URL. Pat
231231
- `:paramName` – matches a URL segment up to the next `/`, `?`, or `#`. The matched string is called a [param](#params)
232232
- `()` – Wraps a portion of the URL that is optional
233233
- `*` – 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)
234235
235236
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.
236237

docs/Troubleshooting.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ You need to add `router` to your component's `contextTypes` to make the router o
66

77
```js
88
contextTypes: {
9-
router: Router.PropTypes.router
9+
router: routerShape.isRequired
1010
}
1111
```
1212

docs/guides/ConfirmingNavigation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ You can prevent a transition from happening or prompt the user before leaving a
66
const Home = React.createClass({
77

88
contextTypes: {
9-
router: Router.PropTypes.router
9+
router: routerShape.isRequired
1010
},
1111

1212
componentDidMount() {

examples/auth-flow-async-with-query-params/app.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import React, { createClass, PropTypes } from 'react'
1+
import React, { createClass } from 'react'
22
import { render } from 'react-dom'
3-
import { Router, Route, IndexRoute, browserHistory, Link } from 'react-router'
3+
import {
4+
Router, Route, IndexRoute, browserHistory, Link, routerShape
5+
} from 'react-router'
46

57
function App(props) {
68
return (
@@ -12,7 +14,7 @@ function App(props) {
1214

1315
const Form = createClass({
1416
contextTypes: {
15-
router: PropTypes.object.isRequired
17+
router: routerShape.isRequired
1618
},
1719

1820
getInitialState() {

examples/auth-flow/app.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react'
22
import { render } from 'react-dom'
3-
import { browserHistory, Router, Route, Link } from 'react-router'
3+
import { browserHistory, Router, Route, Link, routerShape } from 'react-router'
44
import auth from './auth'
55

66
const App = React.createClass({
@@ -58,7 +58,7 @@ const Dashboard = React.createClass({
5858
const Login = React.createClass({
5959

6060
contextTypes: {
61-
router: React.PropTypes.object.isRequired
61+
router: routerShape.isRequired
6262
},
6363

6464
getInitialState() {

examples/confirming-navigation/app.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react'
22
import { render } from 'react-dom'
3-
import { browserHistory, Router, Route, Link } from 'react-router'
3+
import { browserHistory, Router, Route, Link, routerShape } from 'react-router'
44

55
const App = React.createClass({
66
render() {
@@ -24,7 +24,7 @@ const Dashboard = React.createClass({
2424

2525
const Form = React.createClass({
2626
contextTypes: {
27-
router: React.PropTypes.object.isRequired
27+
router: routerShape.isRequired
2828
},
2929

3030
componentWillMount() {

examples/master-detail/app.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import React from 'react'
22
import { render, findDOMNode } from 'react-dom'
3-
import { browserHistory, Router, Route, IndexRoute, Link } from 'react-router'
3+
import {
4+
browserHistory, Router, Route, IndexRoute, Link, routerShape
5+
} from 'react-router'
46
import ContactStore from './ContactStore'
57
import './app.css'
68

@@ -63,7 +65,7 @@ const Index = React.createClass({
6365

6466
const Contact = React.createClass({
6567
contextTypes: {
66-
router: React.PropTypes.object.isRequired
68+
router: routerShape.isRequired
6769
},
6870

6971
getStateFromStore(props) {
@@ -120,7 +122,7 @@ const Contact = React.createClass({
120122

121123
const NewContact = React.createClass({
122124
contextTypes: {
123-
router: React.PropTypes.object.isRequired
125+
router: routerShape.isRequired
124126
},
125127

126128
createContact(event) {

0 commit comments

Comments
 (0)