Skip to content

Commit fe37031

Browse files
committed
Merge branch 'master' into next
2 parents c115a8b + 9c955c5 commit fe37031

File tree

34 files changed

+648
-571
lines changed

34 files changed

+648
-571
lines changed

.eslintrc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
{
2-
"extends": "rackt",
2+
"extends": ["rackt", "plugin:react/recommended"],
33
"globals": {
44
"__DEV__": true
55
},
66
"rules": {
7-
"react/jsx-uses-react": 1,
8-
"react/jsx-no-undef": 2,
7+
"react/display-name": 0,
98
"react/wrap-multilines": 2
109
},
1110
"plugins": [

CHANGES.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,39 @@
1414
[#3446]: https://github.com/reactjs/react-router/pull/3446
1515

1616

17+
## [v2.5.2]
18+
> Jul 1, 2016
19+
20+
- **Bugfix:** Remove extraneous `propTypes` check when creating a route object from a React element ([#3591])
21+
22+
[v2.5.2]: https://github.com/reactjs/react-router/compare/v2.5.1...v2.5.2
23+
[#3591]: https://github.com/reactjs/react-router/pull/3591
24+
25+
26+
## [v2.5.1]
27+
> Jun 23, 2016
28+
29+
- **Bugfix:** Throw error instead of silently failing with history v3 ([#3571])
30+
- **Bugfix:** Explicitly throw error in `onClick` handler of `<Link>` rendered outside of router context ([#3572])
31+
32+
[v2.5.1]: https://github.com/reactjs/react-router/compare/v2.5.0...v2.5.1
33+
[#3571]: https://github.com/reactjs/react-router/pull/3571
34+
[#3572]: https://github.com/reactjs/react-router/pull/3572
35+
36+
37+
## [v2.5.0]
38+
> Jun 22, 2016
39+
40+
- **Feature/Deprecation:** Call `getChildRoutes` and `getIndexRoute` with `partialNextState`; deprecate accessing `location` directly in favor of `partialNextState.location` there ([#3556], [#3561], [#3569], [Upgrade Guide](/upgrade-guides/v2.5.0.md#getchildroutes-getindexroute-signature))
41+
- **Refactor:** Refactor creating `routeParams` objects ([#3544])
42+
43+
[v2.5.0]: https://github.com/reactjs/react-router/compare/v2.4.1...v2.5.0
44+
[#3544]: https://github.com/reactjs/react-router/pull/3544
45+
[#3556]: https://github.com/reactjs/react-router/pull/3556
46+
[#3561]: https://github.com/reactjs/react-router/pull/3561
47+
[#3569]: https://github.com/reactjs/react-router/pull/3569
48+
49+
1750
## [v2.4.1]
1851
> May 19, 2016
1952

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2015 Ryan Florence, Michael Jackson
3+
Copyright (c) 2015-present, Ryan Florence, Michael Jackson
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ render((
120120
<Route path="*" component={NoMatch}/>
121121
</Route>
122122
</Router>
123-
), document.body)
123+
), document.getElementById('root'))
124124
```
125125

126126
See more in the [Introduction](/docs/Introduction.md), [Guides](/docs/guides/README.md), and [Examples](/examples).

docs/API.md

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,8 @@ function createElement(Component, props) {
7070
}
7171
```
7272

73-
##### `stringifyQuery(queryObject)`
74-
A function used to convert an object from [`<Link>`](#link)s or calls to
75-
[`transitionTo`](#transitiontopathname-query-state) to a URL query string.
76-
77-
##### `parseQueryString(queryString)`
78-
A function used to convert a query string into an object that gets passed to route component props.
79-
8073
##### `onError(error)`
81-
While the router is matching, errors may bubble up, here is your opportunity to catch and deal with them. Typically these will come from async features like [`route.getComponents`](#getcomponentsnextstate-callback), [`route.getIndexRoute`](#getindexroutelocation-callback), and [`route.getChildRoutes`](#getchildrouteslocation-callback).
74+
While the router is matching, errors may bubble up, here is your opportunity to catch and deal with them. Typically these will come from async features like [`route.getComponents`](#getcomponentsnextstate-callback), [`route.getIndexRoute`](#getindexroutepartialnextstate-callback), and [`route.getChildRoutes`](#getchildroutespartialnextstate-callback).
8275

8376
##### `onUpdate()`
8477
Called whenever the router updates its state in response to URL changes.
@@ -88,6 +81,10 @@ This is primarily for integrating with other libraries that need to participate
8881

8982
Ensure that you render a `<RouterContext>` at the end of the line, passing all the props passed to `render`.
9083

84+
##### `stringifyQuery(queryObject)` (deprecated)
85+
86+
##### `parseQueryString(queryString)` (deprecated)
87+
9188

9289
#### Examples
9390
Please see the [`examples/`](/examples) directory of the repository for extensive examples of using `<Router>`.
@@ -101,7 +98,7 @@ A `<Link>` can know when the route it links to is active and automatically apply
10198

10299
#### Props
103100
##### `to`
104-
A [location descriptor](https://github.com/mjackson/history/blob/master/docs/Glossary.md#locationdescriptor). Usually this is a string or an object, with the following semantics:
101+
A [location descriptor](https://github.com/ReactJSTraining/history/blob/master/docs/Glossary.md#locationdescriptor). Usually this is a string or an object, with the following semantics:
105102

106103
* If it's a string it represents the absolute path to link to, e.g. `/users/123` (relative paths are not supported).
107104
* If it's an object it can have four keys:
@@ -110,7 +107,7 @@ A [location descriptor](https://github.com/mjackson/history/blob/master/docs/Glo
110107
* `hash`: A hash to put in the URL, e.g. `#a-hash`.
111108
* `state`: State to persist to the `location`.
112109

113-
_Note: React Router currently does not manage scroll position, and will not scroll to the element corresponding to the hash.
110+
_Note: React Router currently does not manage scroll position, and will not scroll to the element corresponding to `hash`._
114111

115112
##### `activeClassName`
116113
The className a `<Link>` receives when its route is active. No active class by default.
@@ -127,6 +124,12 @@ If `true`, the `<Link>` will only be active when the current route exactly match
127124
##### *others*
128125
You can also pass props you'd like to be on the `<a>` such as a `title`, `id`, `className`, etc.
129126

127+
##### `query` **([deprecated](/upgrade-guides/v2.0.0.md#link-to-onenter-and-isactive-use-location-descriptors) see `to`)**
128+
129+
##### `hash` **([deprecated](/upgrade-guides/v2.0.0.md#link-to-onenter-and-isactive-use-location-descriptors) see `to`)**
130+
131+
##### `state` **([deprecated](/upgrade-guides/v2.0.0.md#link-to-onenter-and-isactive-use-location-descriptors) see `to`)**
132+
130133
#### Example
131134
Given a route like `<Route path="/users/:userId" />`:
132135

@@ -185,6 +188,18 @@ Go back one entry in the history.
185188
##### `goForward()`
186189
Go forward one entry in the history.
187190

191+
##### `setRouteLeaveHook(route, hook)`
192+
Registers the given hook function to run before leaving the given route.
193+
194+
During a normal transition, the hook function receives the next location as its only argument and can return either a prompt message (string) to show the user, to make sure they want to leave the page; or `false`, to prevent the transition. Any other return value will have no effect.
195+
196+
During the beforeunload event (in browsers) the hook receives no arguments.
197+
In this case it must return a prompt message to prevent the transition.
198+
199+
Returns a function that may be used to unbind the listener.
200+
201+
You don't need to manually tear down the route leave hook in most cases. We automatically remove all attached route leave hooks after leaving the associated route.
202+
188203
##### `createPath(pathOrLoc, query)`
189204
Stringifies the query into the pathname, using the router's config.
190205

@@ -289,8 +304,7 @@ class Users extends React.Component {
289304
```
290305

291306
##### `getComponent(nextState, callback)`
292-
Same as `component` but asynchronous, useful for
293-
code-splitting.
307+
Same as `component` but asynchronous, useful for code-splitting.
294308

295309
###### `callback` signature
296310
`cb(err, component)`
@@ -340,8 +354,8 @@ A plain JavaScript object route definition. `<Router>` turns JSX `<Route>`s into
340354
##### `childRoutes`
341355
An array of child routes, same as `children` in JSX route configs.
342356

343-
##### `getChildRoutes(location, callback)`
344-
Same as `childRoutes` but asynchronous and receives the `location`. Useful for code-splitting and dynamic route matching (given some state or session data to return a different set of child routes).
357+
##### `getChildRoutes(partialNextState, callback)`
358+
Same as `childRoutes` but asynchronous and receives `partialNextState`. Useful for code-splitting and dynamic route matching (given some state or session data to return a different set of child routes).
345359

346360
###### `callback` signature
347361
`cb(err, routesArray)`
@@ -371,8 +385,8 @@ let myRoute = {
371385

372386
let myRoute = {
373387
path: 'picture/:id',
374-
getChildRoutes(location, cb) {
375-
let { state } = location
388+
getChildRoutes(partialNextState, cb) {
389+
let { state } = partialNextState
376390

377391
if (state && state.fromDashboard) {
378392
cb(null, [dashboardPictureRoute])
@@ -386,9 +400,9 @@ let myRoute = {
386400
##### `indexRoute`
387401
The [index route](/docs/guides/IndexRoutes.md). This is the same as specifying an `<IndexRoute>` child when using JSX route configs.
388402

389-
##### `getIndexRoute(location, callback)`
403+
##### `getIndexRoute(partialNextState, callback)`
390404

391-
Same as `indexRoute`, but asynchronous and receives the `location`. As with `getChildRoutes`, this can be useful for code-splitting and dynamic route matching.
405+
Same as `indexRoute`, but asynchronous and receives `partialNextState`. As with `getChildRoutes`, this can be useful for code-splitting and dynamic route matching.
392406

393407
###### `callback` signature
394408
`cb(err, route)`
@@ -407,7 +421,7 @@ let myRoute = {
407421
// async index route
408422
let myRoute = {
409423
path: 'courses',
410-
getIndexRoute(location, cb) {
424+
getIndexRoute(partialNextState, cb) {
411425
// do something async here
412426
cb(null, myIndexRoute)
413427
}
@@ -587,9 +601,9 @@ For more details, please see the [histories guide](/docs/guides/Histories.md).
587601
`useRouterHistory` is a `history` enhancer that configures a given `createHistory` factory to work with React Router. This allows using custom histories in addition to the bundled singleton histories.
588602

589603
It also pre-enhances the history with the
590-
[useQueries](https://github.com/mjackson/history/blob/master/docs/QuerySupport.md)
604+
[useQueries](https://github.com/ReactJSTraining/history/blob/master/docs/QuerySupport.md)
591605
and
592-
[useBasename](https://github.com/mjackson/history/blob/master/docs/BasenameSupport.md)
606+
[useBasename](https://github.com/ReactJSTraining/history/blob/master/docs/BasenameSupport.md)
593607
enhancers from `history`
594608

595609
#### Example

docs/Glossary.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ type Router = {
244244
go(n: number) => void;
245245
goBack() => void;
246246
goForward() => void;
247-
setRouteLeaveHook(hook: RouteHook) => Function;
247+
setRouteLeaveHook(route: Route, hook: RouteHook) => Function;
248248
isActive(location: LocationDescriptor, indexOnly: boolean) => void;
249249
};
250250
```

docs/guides/DynamicRouting.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ A router is the perfect place to handle code splitting: it's responsible for set
1010

1111
React Router does all of its [path matching](/docs/guides/RouteMatching.md) and component fetching asynchronously, which allows you to not only load up the components lazily, *but also lazily load the route configuration*. You really only need one route definition in your initial bundle, the router can resolve the rest on demand.
1212

13-
Routes may define [`getChildRoutes`](/docs/API.md#getchildrouteslocation-callback), [`getIndexRoute`](/docs/API.md#getindexroutelocation-callback), and [`getComponents`](/docs/API.md#getcomponentsnextstate-callback) methods. These are asynchronous and only called when needed. We call it "gradual matching". React Router will gradually match the URL and fetch only the amount of route configuration and components it needs to match the URL and render.
13+
Routes may define [`getChildRoutes`](/docs/API.md#getchildroutespartialnextstate-callback), [`getIndexRoute`](/docs/API.md#getindexroutepartialnextstate-callback), and [`getComponents`](/docs/API.md#getcomponentsnextstate-callback) methods. These are asynchronous and only called when needed. We call it "gradual matching". React Router will gradually match the URL and fetch only the amount of route configuration and components it needs to match the URL and render.
1414

1515
Coupled with a smart code splitting tool like [webpack](http://webpack.github.io/), a once tiresome architecture is now simple and declarative.
1616

1717
```js
1818
const CourseRoute = {
1919
path: 'course/:courseId',
2020

21-
getChildRoutes(location, callback) {
21+
getChildRoutes(partialNextState, callback) {
2222
require.ensure([], function (require) {
2323
callback(null, [
2424
require('./routes/Announcements'),
@@ -28,7 +28,7 @@ const CourseRoute = {
2828
})
2929
},
3030

31-
getIndexRoute(location, callback) {
31+
getIndexRoute(partialNextState, callback) {
3232
require.ensure([], function (require) {
3333
callback(null, {
3434
component: require('./components/Index'),

docs/guides/Histories.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,11 @@ render(
139139

140140
If you'd like to further customize the history options or use other
141141
enhancers from
142-
[history](https://github.com/mjackson/history/) you can use
142+
[history](https://github.com/ReactJSTraining/history/) you can use
143143
`useRouterHistory`.
144144

145145
Be aware that `useRouterHistory` already pre-enhances your history
146-
factory with the [useQueries](https://github.com/mjackson/history/blob/master/docs/QuerySupport.md) and [useBasename](https://github.com/mjackson/history/blob/master/docs/BasenameSupport.md) enhancers from `history`.
146+
factory with the [useQueries](https://github.com/ReactJSTraining/history/blob/master/docs/QuerySupport.md) and [useBasename](https://github.com/ReactJSTraining/history/blob/master/docs/BasenameSupport.md) enhancers from `history`.
147147

148148
### Examples:
149149

examples/.eslintrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"rules": {
3+
"react/prop-types": 0
4+
}
5+
}

examples/active-links/app.js

Lines changed: 43 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,60 @@
1-
import React, { Component } from 'react'
1+
import React from 'react'
22
import { render } from 'react-dom'
33
import { Router, Route, IndexRoute, Link, IndexLink, browserHistory } from 'react-router'
44

55
const ACTIVE = { color: 'red' }
66

7-
class App extends Component {
8-
render() {
9-
return (
10-
<div>
11-
<h1>APP!</h1>
12-
<ul>
13-
<li><Link to="/" activeStyle={ACTIVE}>/</Link></li>
14-
<li><IndexLink to="/" activeStyle={ACTIVE}>/ IndexLink</IndexLink></li>
7+
const App = ({ children }) => (
8+
<div>
9+
<h1>APP!</h1>
10+
<ul>
11+
<li><Link to="/" activeStyle={ACTIVE}>/</Link></li>
12+
<li><IndexLink to="/" activeStyle={ACTIVE}>/ IndexLink</IndexLink></li>
1513

16-
<li><Link to="/users" activeStyle={ACTIVE}>/users</Link></li>
17-
<li><IndexLink to="/users" activeStyle={ACTIVE}>/users IndexLink</IndexLink></li>
14+
<li><Link to="/users" activeStyle={ACTIVE}>/users</Link></li>
15+
<li><IndexLink to="/users" activeStyle={ACTIVE}>/users IndexLink</IndexLink></li>
1816

19-
<li><Link to="/users/ryan" activeStyle={ACTIVE}>/users/ryan</Link></li>
20-
<li><Link to={{ pathname: '/users/ryan', query: { foo: 'bar' } }}
21-
activeStyle={ACTIVE}>/users/ryan?foo=bar</Link></li>
17+
<li><Link to="/users/ryan" activeStyle={ACTIVE}>/users/ryan</Link></li>
18+
<li><Link to={{ pathname: '/users/ryan', query: { foo: 'bar' } }}
19+
activeStyle={ACTIVE}>/users/ryan?foo=bar</Link></li>
2220

23-
<li><Link to="/about" activeStyle={ACTIVE}>/about</Link></li>
24-
</ul>
21+
<li><Link to="/about" activeStyle={ACTIVE}>/about</Link></li>
22+
</ul>
2523

26-
{this.props.children}
27-
</div>
28-
)
29-
}
30-
}
24+
{children}
25+
</div>
26+
)
3127

32-
class Index extends React.Component {
33-
render() {
34-
return (
35-
<div>
36-
<h2>Index!</h2>
37-
</div>
38-
)
39-
}
40-
}
28+
const Index = () => (
29+
<div>
30+
<h2>Index!</h2>
31+
</div>
32+
)
4133

42-
class Users extends React.Component {
43-
render() {
44-
return (
45-
<div>
46-
<h2>Users</h2>
47-
{this.props.children}
48-
</div>
49-
)
50-
}
51-
}
34+
const Users = ({ children }) => (
35+
<div>
36+
<h2>Users</h2>
37+
{children}
38+
</div>
39+
)
5240

53-
class UsersIndex extends React.Component {
54-
render() {
55-
return (
56-
<div>
57-
<h3>UsersIndex</h3>
58-
</div>
59-
)
60-
}
61-
}
41+
const UsersIndex = () => (
42+
<div>
43+
<h3>UsersIndex</h3>
44+
</div>
45+
)
6246

63-
class User extends React.Component {
64-
render() {
65-
return (
66-
<div>
67-
<h3>User {this.props.params.id}</h3>
68-
</div>
69-
)
70-
}
71-
}
47+
const User = ({ params: { id } }) => (
48+
<div>
49+
<h3>User {id}</h3>
50+
</div>
51+
)
7252

73-
class About extends React.Component {
74-
render() {
75-
return (
76-
<div>
77-
<h2>About</h2>
78-
</div>
79-
)
80-
}
81-
}
53+
const About = () => (
54+
<div>
55+
<h2>About</h2>
56+
</div>
57+
)
8258

8359
render((
8460
<Router history={browserHistory}>

0 commit comments

Comments
 (0)