Skip to content

Commit 674a1d4

Browse files
committed
Merge branch 'master' into next
2 parents 5f3387a + c02c846 commit 674a1d4

22 files changed

+186
-99
lines changed

.babelrc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
2-
"presets": ["stage-0", "react"],
2+
"presets": ["react"],
33
"plugins": ["dev-expression"],
44

55
"env": {
66
"cjs": {
7-
"presets": ["es2015-loose"],
7+
"presets": ["es2015-loose", "stage-1"],
88
"plugins": ["add-module-exports"]
99
},
1010
"es": {
11-
"presets": ["es2015-loose-native-modules"]
11+
"presets": ["es2015-loose-native-modules", "stage-1"]
1212
}
1313
}
1414
}

CHANGES.md

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
1+
## [v2.4.0]
2+
> April 28, 2016
3+
4+
- **Feature:** Add `withRouter` higher-order component for injecting `props.router` ([#3352])
5+
- **Minor:** Add React as a peer dependency ([#3361])
6+
- **Minor:** Upgrade to Babel 6 ([#3362])
7+
- **Minor:** Add `target` to `propTypes` for `<Link>` ([#3397])
8+
9+
[v2.4.0]: https://github.com/reactjs/react-router/compare/v2.3.0...v2.4.0
10+
[#3352]: https://github.com/reactjs/react-router/pull/3352
11+
[#3361]: https://github.com/reactjs/react-router/pull/3361
12+
[#3362]: https://github.com/reactjs/react-router/pull/3362
13+
[#3397]: https://github.com/reactjs/react-router/pull/3397
14+
15+
116
## [v2.3.0]
217
> April 18, 2016
318
419
- **Feature:** Add `applyRouterMiddleware` for extending router rendering ([#3327])
520
- **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])
21+
- **Minor:** Move ES module build back to `es6/` to avoid breaking people who were importing from `react-router/es6` ([#3334])
722

823
[v2.3.0]: https://github.com/reactjs/react-router/compare/v2.2.4...v2.3.0
9-
[#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
24+
[#3327]: https://github.com/reactjs/react-router/pull/3327
25+
[#3334]: https://github.com/reactjs/react-router/pull/3334
26+
[#3349]: https://github.com/reactjs/react-router/pull/3349
1227

1328

1429
## [v2.2.4]

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# React Router [![Travis][build-badge]][build] [![npm package][npm-badge]][npm]
22

3+
<img src="/logo/[email protected]" height="150"/>
4+
35
React Router is a complete routing library for [React](https://facebook.github.io/react).
46

57
React Router keeps your UI in sync with the URL. It has a simple API with powerful features like lazy code loading, dynamic route matching, and location transition handling built right in. Make the URL your first thought, not an after-thought.
@@ -20,7 +22,7 @@ React Router keeps your UI in sync with the URL. It has a simple API with powerf
2022

2123
**Older Versions:**
2224

23-
- 0.13.x - [docs](https://github.com/reactjs/react-router/tree/0.13.x/docs/guides) / [code](https://github.com/reactjs/react-router/tree/0.13.x) / [upgrade guide](https://github.com/reactjs/react-router/blob/master/upgrade-guides/v1.0.0.md)
25+
- 0.13.x - [docs](https://github.com/reactjs/react-router/tree/0.13.x/doc) / [guides](https://github.com/reactjs/react-router/tree/0.13.x/docs/guides) / [code](https://github.com/reactjs/react-router/tree/0.13.x) / [upgrade guide](https://github.com/reactjs/react-router/blob/master/upgrade-guides/v1.0.0.md)
2426
- 1.0.x - [docs](https://github.com/reactjs/react-router/tree/1.0.x/docs) / [code](https://github.com/reactjs/react-router/tree/1.0.x) / [upgrade guide](https://github.com/reactjs/react-router/blob/master/upgrade-guides/v2.0.0.md)
2527

2628
For questions and support, please visit [our channel on Reactiflux](https://discord.gg/0ZcbPKXt5bYaNQ46) or [Stack Overflow](http://stackoverflow.com/questions/tagged/react-router).
@@ -64,7 +66,7 @@ import { Router, Route, Link, browserHistory } from 'react-router'
6466

6567
const App = React.createClass({/*...*/})
6668
const About = React.createClass({/*...*/})
67-
// etc.
69+
const NoMatch = React.createClass({/*...*/})
6870

6971
const Users = React.createClass({
7072
render() {

docs/API.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
- [`<Router>`](#router)
55
- [`<Link>`](#link)
66
- [`<IndexLink>`](#indexlink)
7-
- [`withRouter`](#withRouter-component)
7+
- [`withRouter`](#withroutercomponent)
88
- [`<RouterContext>`](#routercontext)
99
- [`context.router`](#contextrouter)
1010

@@ -252,7 +252,7 @@ const routes = (
252252
<Route component={App}>
253253
<Route path="groups" components={{main: Groups, sidebar: GroupsSidebar}} />
254254
<Route path="users" components={{main: Users, sidebar: UsersSidebar}}>
255-
<Route path="users/:userId" component={Profile} />
255+
<Route path=":userId" component={Profile} />
256256
</Route>
257257
</Route>
258258
)

docs/Troubleshooting.md

Lines changed: 70 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ const App = React.createClass({
3131
})
3232
```
3333

34+
3435
### Component won't render
3536

36-
Route matching happens in the order they are defined (think `if/elseif` statement). In this case, `/about/me` will show the `<UserPage>` component because `/about/me` matches the first route. You need to reorder your routes if this happens. `<About>` will never be reachable:
37+
Route matching happens in the order they are defined (think `if/else if` statement). In this case, `/about/me` will show the `<UserPage>` component because `/about/me` matches the first route. You need to reorder your routes if this happens. `<About>` will never be reachable:
3738

3839
```js
3940
<Router>
@@ -52,22 +53,83 @@ Route matching happens in the order they are defined (think `if/elseif` statemen
5253
```
5354

5455

56+
### Parent path does not show as active
57+
58+
If your routes look like:
59+
60+
```js
61+
<Route path="/">
62+
<Route path="widgets" component={WidgetList} />
63+
<Route path="widgets/:widgetId" component={Widget} />
64+
</Route>
65+
```
66+
67+
Then the path `/widgets` will not be considered active when the current path is something like `/widgets/3`. This is because React Router looks at parent _routes_ rather than parent _paths_ to determine active state. To make the path `/widgets` active when the current path is `/widgets/3`, you need to declare your routes as:
68+
69+
```js
70+
<Route path="/">
71+
<Route path="widgets">
72+
<IndexRoute component={WidgetList} />
73+
<Route path=":widgetId" component={Widget} />
74+
</Route>
75+
</Route>
76+
```
77+
78+
As an additional benefit, this also removes the duplication in declaring route paths.
79+
80+
5581
### "Required prop was not specified" on route components
5682

5783
You might see this if you are using `React.cloneElement` to inject props into route components from their parents. If you see this, remove `isRequired` from `propTypes` for those props. This happens because React validates `propTypes` when the element is created rather than when it is mounted. For more details, see [facebook/react#4494](https://github.com/facebook/react/issues/4494#issuecomment-125068868).
5884

5985
You should generally attempt to use this pattern as sparingly as possible. In general, it's best practice to minimize data dependencies between route components.
6086

6187

62-
### `<noscript>` with server-side rendering and async routes
88+
### Passing additional values into route components
6389

64-
Use `match({ history, routes })` on the client side. See [the server rendering guide](guides/ServerRendering.md#async-routes).
90+
There are multiple ways to do this depending on what you want specifically.
6591

92+
#### Declare properties on the route
6693

67-
### Passing additional values into route components
94+
You can define additional props on `<Route>` or on the plain route:
6895

69-
There are multiple ways to do this depending on what you want to do. You can:
96+
```js
97+
<Route foo="bar" />
98+
```
7099

71-
- Define additional values on `<Route>` or the plain route. This will make those values available on `this.props.route` on route components.
72-
- Pass in a `createElement` handler to `<Router>` or `<RouterContext>`. This will allow you to inject additional props into route elements at creation time.
73-
- Define a top-level component above `<Router>` or `<RouterContext>` that exports additional values via `getChildContext`, then access them via context from rendered components.
100+
These properties will then be available on `this.props.route` on the route component, such as with `this.props.route.foo` above.
101+
102+
#### Inject props to all routes via middleware
103+
104+
You can define a middleware that injects additional props into each route component:
105+
106+
```js
107+
const useExtraProps = {
108+
renderRouteComponent: child => React.cloneElement(child, extraProps)
109+
}
110+
```
111+
112+
You can then use this middleware with:
113+
114+
```js
115+
<Router
116+
history={history}
117+
routes={routes}
118+
render={applyRouterMiddleware(useExtraProps)}
119+
/>
120+
```
121+
122+
#### Use a top-level context provider
123+
124+
You can export React context on a top-level provider component, then access this data throughout the tree on rendered components.
125+
126+
```js
127+
<ExtraDataProvider>
128+
<Router history={history} routes={routes} />
129+
</ExtraDataProvider>
130+
```
131+
132+
133+
### `<noscript>` with server-side rendering and async routes
134+
135+
Use `match({ history, routes })` on the client side. See [the server rendering guide](guides/ServerRendering.md#async-routes).

docs/guides/ConfirmingNavigation.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@ const Home = withRouter(
2222
})
2323
)
2424
```
25+
26+
Note that this example makes use of the [withRouter](https://github.com/reactjs/react-router/blob/v2.4.0/upgrade-guides/v2.4.0.md) higher-order component introduced in v2.4.0.
Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
11
# Minimizing Bundle Size
22

3-
For convenience, React Router exposes its full API on the top-level `react-router` import. However, this causes the entire React Router library and its dependencies to be included in client bundles that include code that makes any imports from the top-level CommonJS bundle.
3+
For convenience, React Router exposes its full API on the top-level `react-router` import. However, this causes the entire React Router library and its dependencies to be included in client bundles that include code that imports from the top-level CommonJS bundle.
44

5-
There are two options for minimizing client bundle size by excluding unused modules.
5+
Instead, the bindings exported from `react-router` are also available in `react-router/lib`. When using CommonJS modules, you can import directly from `react-router/lib` to avoid pulling in unused modules.
66

7-
8-
## Import from `react-router/lib`
9-
10-
Bindings exported from `react-router` are also available in `react-router/lib`. When using CommonJS models, you can import directly from `react-router/lib` to avoid pulling in unused modules.
11-
12-
Assuming you are transpiling ES2015 modules into CommonJS modules, instead of
7+
Assuming you are transpiling ES2015 modules into CommonJS modules, instead of:
138

149
```js
1510
import { Link, Route, Router } from 'react-router'
1611
```
1712

18-
use
13+
use:
1914

2015
```js
2116
import Link from 'react-router/lib/Link'
@@ -24,16 +19,3 @@ import Router from 'react-router/lib/Router'
2419
```
2520

2621
The public API available in this manner is defined as the set of imports available from the top-level `react-router` module. Anything not available through the top-level `react-router` module is a private API, and is subject to change without notice.
27-
28-
29-
## Use a Bundler with ES2015 Module Support
30-
31-
React Router offers a ES2015 module build and defines a `jsnext:main` entry point. Only if you are using a bundler that supports ES2015 modules and tree-shaking such as webpack 2 or Rollup, you can directly import from `react-router`, as long as you are correctly resolving to the ES2015 module build. Specifically, in those cases, you can write
32-
33-
```js
34-
import { Link, Route, Router } from 'react-router'
35-
```
36-
37-
Tree-shaking will ensure that only the relevant modules will be included in your bundle.
38-
39-
**Note:** Please do not import from the subdirectory with the ES module build directly. If you are using webpack 2, please add `jsnext:main` to `resolve.mainFields` (or `resolve.packageMains` for older versions of webpack 2).

docs/guides/testing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Firstly, ensure you are using at least the following versions of each package.
2222

2323
Also, make sure you are using node 4.x
2424

25-
In prior setups, react-tools was needed. This is not longer the case. You will need to remove it from your package.json and environment.
25+
In prior setups, react-tools was needed. This is no longer the case. You will need to remove it from your package.json and environment.
2626

2727
```json
2828
"react-tools": "~0.13.3",
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React from 'react'
22

3-
const PageOne = React.createClass({
3+
const PageTwo = React.createClass({
44
render() {
55
return <h2>Page Two! Wooo!</h2>
66
}
77
})
88

9-
export default PageOne
9+
export default PageTwo

examples/index.html

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,28 @@
11
<!doctype html>
2-
<title>React Router Examples</title>
3-
<link href="global.css" rel="stylesheet"/>
2+
<html>
3+
<head>
4+
<title>React Router Examples</title>
5+
<link href="global.css" rel="stylesheet"/>
6+
</head>
47
<body>
5-
<h1>React Router Examples</h1>
6-
<ul>
7-
<li><a href="active-links">Active Links</a></li>
8-
<li><a href="animations">Animations</a></li>
9-
<li><a href="auth-flow">Auth Flow</a></li>
10-
<li><a href="auth-with-shared-root">Auth with Shared Root</a></li>
11-
<li><a href="auth-flow-async-with-query-params">Async Auth with Query Parameters</a></li>
12-
<li><a href="breadcrumbs">Breadcrumbs</a></li>
13-
<li><a href="confirming-navigation">Confirming Navigation</a></li>
14-
<li><a href="dynamic-segments">Dynamic Segments</a></li>
15-
<li><a href="huge-apps">Huge Apps (Partial App Loading)</a></li>
16-
<li><a href="master-detail">Master Detail</a></li>
17-
<li><a href="nested-animations">Nested Animations</a></li>
18-
<li><a href="passing-props-to-children">Passing Props to Children</a></li>
19-
<li><a href="pinterest">Pinterest-style UI (<code>location.state</code>)</a></li>
20-
<li><a href="query-params">Query Params</a></li>
21-
<li><a href="route-no-match">Route Not Found</a></li>
22-
<li><a href="sidebar">Sidebar</a></li>
23-
</ul>
8+
<h1>React Router Examples</h1>
9+
<ul>
10+
<li><a href="active-links">Active Links</a></li>
11+
<li><a href="animations">Animations</a></li>
12+
<li><a href="auth-flow">Auth Flow</a></li>
13+
<li><a href="auth-with-shared-root">Auth with Shared Root</a></li>
14+
<li><a href="auth-flow-async-with-query-params">Async Auth with Query Parameters</a></li>
15+
<li><a href="breadcrumbs">Breadcrumbs</a></li>
16+
<li><a href="confirming-navigation">Confirming Navigation</a></li>
17+
<li><a href="dynamic-segments">Dynamic Segments</a></li>
18+
<li><a href="huge-apps">Huge Apps (Partial App Loading)</a></li>
19+
<li><a href="master-detail">Master Detail</a></li>
20+
<li><a href="nested-animations">Nested Animations</a></li>
21+
<li><a href="passing-props-to-children">Passing Props to Children</a></li>
22+
<li><a href="pinterest">Pinterest-style UI (<code>location.state</code>)</a></li>
23+
<li><a href="query-params">Query Params</a></li>
24+
<li><a href="route-no-match">Route Not Found</a></li>
25+
<li><a href="sidebar">Sidebar</a></li>
26+
</ul>
27+
</body>
28+
</html>

0 commit comments

Comments
 (0)