Skip to content

Commit a3dccec

Browse files
committed
Merge branch 'master' into next
2 parents ec523e4 + caf4685 commit a3dccec

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+407
-221
lines changed

CHANGES.md

+34
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,40 @@
4141
[#3446]: https://github.com/reactjs/react-router/pull/3446
4242

4343

44+
## [v2.8.1]
45+
> Sep 13, 2016
46+
47+
- **Bugfix:** Fix redirects that specify `query` ([#3808])
48+
49+
[v2.8.1]: https://github.com/reactjs/react-router/compare/v2.8.0...v2.8.1
50+
[#3808]: https://github.com/reactjs/react-router/pull/3808
51+
52+
53+
## [v2.8.0]
54+
> Sep 9, 2016
55+
56+
- **Feature:** Support omitting `to` on `<Link>` ([#3803])
57+
- **Refactor:** Use `history.replace` instead of `history.transitionTo` for redirects ([#3799])
58+
59+
[v2.8.0]: https://github.com/reactjs/react-router/compare/v2.7.0...v2.8.0
60+
[#3799]: https://github.com/reactjs/react-router/pull/3799
61+
[#3803]: https://github.com/reactjs/react-router/pull/3803
62+
63+
64+
## [v2.7.0]
65+
> Aug 20, 2016
66+
67+
- **Feature:** Support `router` as a prop on `withRouter`-wrapped components for overriding the router object from context ([#3729])
68+
- **Feature:** Add `withRef` option to `withRouter` that enables `getWrappedInstance` ([#3735], [#3740])
69+
- **Bugfix:** Warn on invalid router middlewares ([#3717])
70+
71+
[v2.7.0]: https://github.com/reactjs/react-router/compare/v2.6.1...v2.7.0
72+
[#3717]: https://github.com/reactjs/react-router/pull/3717
73+
[#3729]: https://github.com/reactjs/react-router/pull/3729
74+
[#3735]: https://github.com/reactjs/react-router/pull/3735
75+
[#3740]: https://github.com/reactjs/react-router/pull/3740
76+
77+
4478
## [v2.6.1]
4579
> Jul 29, 2016
4680

ISSUE_TEMPLATE.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ Have a usage question?
66
The issue tracker isn't the best place for usage questions. This format is not well-suited for Q&A, and questions here don't have as much visibility as they do elsewhere. Before you ask a question, here are some resources to get help first:
77
88
- Do the tutorial: https://github.com/reactjs/react-router-tutorial
9-
- Read the docs: https://github.com/reactjs/react-router/tree/latest/docs
10-
- Explore examples: https://github.com/reactjs/react-router/tree/latest/examples
9+
- Read the docs: https://github.com/ReactTraining/react-router/tree/latest/docs
10+
- Explore examples: https://github.com/ReactTraining/react-router/tree/latest/examples
1111
- Look for/ask questions on stack overflow: https://stackoverflow.com/questions/ask?tags=react-router
1212
- Ask in chat: https://discord.gg/0ZcbPKXt5bYaNQ46
1313
@@ -34,4 +34,3 @@ http://jsbin.com/sacerobuxi/edit?html,js,output
3434
## Expected Behavior
3535

3636
## Actual Behavior
37-

README.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@ React Router keeps your UI in sync with the URL. It has a simple API with powerf
1313
1414
### Docs & Help
1515

16-
- [Tutorial – do this first!](https://github.com/reactjs/react-router-tutorial)
16+
- [Tutorial – do this first!](https://github.com/ReactTraining/react-router-tutorial)
1717
- [Guides and API docs](/docs)
18-
- [Troubleshooting guide](https://github.com/reactjs/react-router/blob/master/docs/Troubleshooting.md)
18+
- [Troubleshooting guide](https://github.com/ReactTraining/react-router/blob/master/docs/Troubleshooting.md)
1919
- [Changelog](/CHANGES.md)
2020
- [Stack Overflow](http://stackoverflow.com/questions/tagged/react-router)
2121
- [CodePen boilerplate](http://codepen.io/anon/pen/xwQZdy?editors=001) for bug reports
2222

2323
**Older Versions:**
2424

25-
- 0.13.x - [docs](https://github.com/reactjs/react-router/tree/v0.13.6/doc) / [guides](https://github.com/reactjs/react-router/tree/v0.13.6/docs/guides) / [code](https://github.com/reactjs/react-router/tree/v0.13.6) / [upgrade guide](https://github.com/reactjs/react-router/blob/master/upgrade-guides/v1.0.0.md)
26-
- 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)
25+
- 0.13.x - [docs](https://github.com/ReactTraining/react-router/tree/v0.13.6/doc) / [guides](https://github.com/ReactTraining/react-router/tree/v0.13.6/docs/guides) / [code](https://github.com/ReactTraining/react-router/tree/v0.13.6) / [upgrade guide](/upgrade-guides/v1.0.0.md)
26+
- 1.0.x - [docs](https://github.com/ReactTraining/react-router/tree/1.0.x/docs) / [code](https://github.com/ReactTraining/react-router/tree/1.0.x) / [upgrade guide](/upgrade-guides/v2.0.0.md)
2727

2828
For questions and support, please visit [our channel on Reactiflux](https://discord.gg/0ZcbPKXt5bYaNQ46) or [Stack Overflow](http://stackoverflow.com/questions/tagged/react-router).
2929

@@ -49,10 +49,10 @@ var Route = require('react-router').Route
4949
var Link = require('react-router').Link
5050
```
5151

52-
The UMD build is also available on [npmcdn](https://npmcdn.com):
52+
The UMD build is also available on [unpkg](https://unpkg.com):
5353

5454
```html
55-
<script src="https://npmcdn.com/react-router/umd/ReactRouter.min.js"></script>
55+
<script src="https://unpkg.com/react-router/umd/ReactRouter.min.js"></script>
5656
```
5757

5858
You can find the library on `window.ReactRouter`.
@@ -127,7 +127,7 @@ See more in the [Introduction](/docs/Introduction.md), [Guides](/docs/guides/REA
127127

128128
### Versioning and Stability
129129

130-
We want React Router to be a stable dependency that’s easy to keep current. We follow the same versioning as React.js itself: [React Versioning Scheme](https://facebook.github.io/react/blog/2016/02/19/new-versioning-scheme.html).
130+
We want React Router to be a stable dependency that’s easy to keep current. We take the same approach to versioning as React.js itself: [React Versioning Scheme](https://facebook.github.io/react/blog/2016/02/19/new-versioning-scheme.html).
131131

132132
### Thanks
133133

@@ -138,14 +138,14 @@ React Router was initially inspired by Ember's fantastic router. Many thanks to
138138

139139
Also, thanks to [BrowserStack](https://www.browserstack.com/) for providing the infrastructure that allows us to run our build in real browsers.
140140

141-
[build-badge]: https://img.shields.io/travis/reactjs/react-router/master.svg?style=flat-square
142-
[build]: https://travis-ci.org/reactjs/react-router
141+
[build-badge]: https://img.shields.io/travis/ReactTraining/react-router/master.svg?style=flat-square
142+
[build]: https://travis-ci.org/ReactTraining/react-router
143143

144144
[npm-badge]: https://img.shields.io/npm/v/react-router.svg?style=flat-square
145145
[npm]: https://www.npmjs.org/package/react-router
146146

147-
[codecov-badge]: https://img.shields.io/codecov/c/github/reactjs/react-router/master.svg?style=flat-square
148-
[codecov]: https://codecov.io/gh/reactjs/react-router
147+
[codecov-badge]: https://img.shields.io/codecov/c/github/ReactTraining/react-router/master.svg?style=flat-square
148+
[codecov]: https://codecov.io/gh/ReactTraining/react-router
149149

150150
[discord-badge]: https://img.shields.io/badge/Discord-join%20chat%20%E2%86%92-738bd7.svg?style=flat-square
151151
[discord]: https://discord.gg/0ZcbPKXt5bYaNQ46

docs/API.md

+41-26
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
- [`<Router>`](#router)
55
- [`<Link>`](#link)
66
- [`<IndexLink>`](#indexlink)
7-
- [`withRouter`](#withroutercomponent)
7+
- [`withRouter`](#withroutercomponent-options)
88
- [`<RouterContext>`](#routercontext)
99
- [`context.router`](#contextrouter)
1010

@@ -46,15 +46,15 @@ Alias for `children`.
4646
##### `history`
4747
The history the router should listen to. Typically `browserHistory` or `hashHistory`.
4848

49-
```jsx
49+
```js
5050
import { browserHistory } from 'react-router'
5151
ReactDOM.render(<Router history={browserHistory} />, el)
5252
```
5353

5454
##### `createElement(Component, props)`
5555
When the router is ready to render a branch of route components, it will use this function to create the elements. You may want to take control of creating the elements when you're using some sort of data abstraction, like setting up subscriptions to stores, or passing in some sort of application module to each component via props.
5656

57-
```jsx
57+
```js
5858
<Router createElement={createElement} />
5959

6060
// default behavior
@@ -94,14 +94,15 @@ A `<Link>` can know when the route it links to is active and automatically apply
9494

9595
#### Props
9696
##### `to`
97-
A [location descriptor](https://github.com/ReactTraining/history/blob/master/docs/Glossary.md#locationdescriptor) or a function that takes the current location and returns a location descriptor. This location descriptor is usually a string or an object, with the following semantics:
97+
A [location descriptor](/docs/Glossary.md#locationdescriptor). Usually this is a string or an object, with the following semantics:
9898

9999
* If it's a string it represents the absolute path to link to, e.g. `/users/123` (relative paths are not supported).
100100
* If it's an object it can have four keys:
101101
* `pathname`: A string representing the path to link to.
102102
* `query`: An object of key:value pairs to be stringified.
103103
* `hash`: A hash to put in the URL, e.g. `#a-hash`.
104104
* `state`: State to persist to the `location`.
105+
* If it is not specified, an anchor tag without an `href` attribute will be rendered.
105106

106107
_Note: React Router currently does not manage scroll position, and will not scroll to the element corresponding to `hash`._
107108

@@ -140,7 +141,7 @@ You can also pass props you'd like to be on the `<a>` such as a `title`, `id`, `
140141
#### Example
141142
Given a route like `<Route path="/users/:userId" />`:
142143

143-
```jsx
144+
```js
144145
<Link to={`/users/${user.id}`} activeClassName="active">{user.name}</Link>
145146
// becomes one of these depending on your History and if the route is
146147
// active
@@ -157,8 +158,22 @@ Given a route like `<Route path="/users/:userId" />`:
157158
### `<IndexLink>`
158159
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.
159160

160-
### `withRouter(component)`
161-
A HoC (higher-order component) that wraps another component to provide `props.router`, `props.params`, `props.location`, and `props.routes`. Pass in your component and it will return the wrapped component.
161+
### `withRouter(Component, [options])`
162+
A HoC (higher-order component) that wraps another component to provide `props.router`. Pass in your component and it will return the wrapped component.
163+
164+
You can explicit specify `router` as a prop to the wrapper component to override the router object from context.
165+
166+
#### Options
167+
168+
##### `withRef`
169+
If `true`, the wrapper component attaches a ref to the wrapped component, which can then be accessed via `getWrappedInstance`.
170+
171+
```js
172+
const WrapperComponent = withRouter(MyComponent, { withRef: true })
173+
174+
// Given a `wrapperInstance` that is of type `WrapperComponent`:
175+
const myInstance = wrapperInstance.getWrappedInstance()
176+
```
162177

163178
### `<RouterContext>`
164179
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.
@@ -172,7 +187,7 @@ Contains data and methods relevant to routing. Most useful for imperatively tran
172187
##### `push(pathOrLoc)`
173188
Transitions to a new URL, adding a new entry in the browser history.
174189

175-
```jsx
190+
```js
176191
router.push('/users/12')
177192

178193
// or with a location descriptor object
@@ -242,9 +257,9 @@ If left undefined, the router will try to match the child routes.
242257
A single component to be rendered when the route matches the URL. It can
243258
be rendered by the parent route component with `this.props.children`.
244259

245-
```jsx
260+
```js
246261
const routes = (
247-
<Route component={App}>
262+
<Route path="/" component={App}>
248263
<Route path="groups" component={Groups} />
249264
<Route path="users" component={Users} />
250265
</Route>
@@ -265,13 +280,13 @@ class App extends React.Component {
265280
##### `components`
266281
Routes can define one or more named components as an object of `[name]: component` pairs to be rendered when the path matches the URL. They can be rendered by the parent route component with `this.props[name]`.
267282

268-
```jsx
283+
```js
269284
// Think of it outside the context of the router - if you had pluggable
270285
// portions of your `render`, you might do it like this:
271286
// <App main={<Users />} sidebar={<UsersSidebar />} />
272287

273288
const routes = (
274-
<Route component={App}>
289+
<Route path="/" component={App}>
275290
<Route path="groups" components={{main: Groups, sidebar: GroupsSidebar}} />
276291
<Route path="users" components={{main: Users, sidebar: UsersSidebar}}>
277292
<Route path=":userId" component={Profile} />
@@ -316,7 +331,7 @@ Same as `component` but asynchronous, useful for code-splitting.
316331
###### `callback` signature
317332
`cb(err, component)`
318333

319-
```jsx
334+
```js
320335
<Route path="courses/:courseId" getComponent={(nextState, cb) => {
321336
// do asynchronous stuff to find the components
322337
cb(null, Course)
@@ -330,7 +345,7 @@ code-splitting.
330345
###### `callback` signature
331346
`cb(err, components)`
332347

333-
```jsx
348+
```js
334349
<Route path="courses/:courseId" getComponents={(nextState, cb) => {
335350
// do asynchronous stuff to find the components
336351
cb(null, {sidebar: CourseSidebar, content: Course})
@@ -348,7 +363,7 @@ If `callback` is listed as a 3rd argument, this hook will run asynchronously, an
348363
###### `callback` signature
349364
`cb(err)`
350365

351-
```jsx
366+
```js
352367
const userIsInATeam = (nextState, replace, callback) => {
353368
fetch(...)
354369
.then(response = response.json())
@@ -389,7 +404,7 @@ Same as `childRoutes` but asynchronous and receives `partialNextState`. Useful f
389404
###### `callback` signature
390405
`cb(err, routesArray)`
391406

392-
```jsx
407+
```js
393408
let myRoute = {
394409
path: 'course/:courseId',
395410
childRoutes: [
@@ -436,7 +451,7 @@ Same as `indexRoute`, but asynchronous and receives `partialNextState`. As with
436451
###### `callback` signature
437452
`cb(err, route)`
438453

439-
```jsx
454+
```js
440455
// For example:
441456
let myIndexRoute = {
442457
component: MyIndex
@@ -472,7 +487,7 @@ The path you want to redirect to.
472487
##### `query`
473488
By default, the query parameters will just pass through but you can specify them if you need to.
474489

475-
```jsx
490+
```js
476491
// Say we want to change from `/profile/123` to `/about/123`
477492
// and redirect `/get-in-touch` to `/contact`
478493
<Route component={App}>
@@ -484,7 +499,7 @@ By default, the query parameters will just pass through but you can specify them
484499

485500
Note that the `<Redirect>` can be placed anywhere in the route hierarchy, though [normal precedence](/docs/guides/RouteMatching.md#precedence) rules apply. If you'd prefer the redirects to be next to their respective routes, the `from` path will match the same as a regular route `path`.
486501

487-
```jsx
502+
```js
488503
<Route path="course/:courseId">
489504
<Route path="dashboard" />
490505
{/* /course/123/home -> /course/123/dashboard */}
@@ -520,7 +535,7 @@ A route's component is rendered when that route matches the URL. The router will
520535
### Injected Props
521536

522537
#### `location`
523-
The current [location](https://github.com/reactjs/history/blob/master/docs/Location.md).
538+
The current [location](https://github.com/mjackson/history/blob/v2.x/docs/Location.md).
524539

525540
#### `params`
526541
The dynamic segments of the URL.
@@ -532,13 +547,13 @@ The route that rendered this component.
532547
Contains methods relevant to routing. Most useful for imperatively transitioning around the application.
533548

534549
#### `routeParams`
535-
A subset of `this.props.params` that were directly specified in this component's route. For example, if the route's path is `users/:userId` and the URL is `/users/123/portfolios/345` then `this.props.routeParams` will be `{userId: '123'}`, and `this.props.params` will be `{userId: '123', portfolioId: 345}`.
550+
A subset of `this.props.params` that were directly specified in this component's route. For example, if the route's path is `users/:userId` and the URL is `/users/123/portfolios/345` then `this.props.routeParams` will be `{userId: '123'}`, and `this.props.params` will be `{userId: '123', portfolioId: '345'}`.
536551

537552
#### `children`
538553
The matched child route element to be rendered. If the route has [named components](/docs/API.md#named-components) then this will be undefined, and the components will instead be available as direct properties on `this.props`.
539554

540555
##### Example
541-
```jsx
556+
```js
542557
render((
543558
<Router>
544559
<Route path="/" component={App}>
@@ -564,7 +579,7 @@ class App extends React.Component {
564579
When a route has one or more named components, the child elements are available by name on `this.props`. In this case `this.props.children` will be undefined. All route components can participate in the nesting.
565580

566581
#### Example
567-
```jsx
582+
```js
568583
render((
569584
<Router>
570585
<Route path="/" component={App}>
@@ -622,7 +637,7 @@ For more details, please see the [histories guide](/docs/guides/Histories.md).
622637
`hashHistory` uses URL hashes, along with a query key to keep track of state. `hashHistory` requires no additional server configuration, but is generally less preferred than `browserHistory`.
623638

624639

625-
### `createMemoryHistory(options)`
640+
### `createMemoryHistory([options])`
626641
`createMemoryHistory` creates an in-memory `history` object that does not interact with the browser URL. This is useful for when you need to customize the `history` object used for server-side rendering, for automated testing, or for when you do not want to manipulate the browser URL, such as when your application is embedded in an `<iframe>`.
627642

628643

@@ -636,7 +651,7 @@ and
636651
enhancers from `history`
637652

638653
#### Example
639-
```jsx
654+
```js
640655
import createHashHistory from 'history/lib/createHashHistory'
641656
const history = useRouterHistory(createHashHistory)({ queryKey: false })
642657
```
@@ -645,7 +660,7 @@ const history = useRouterHistory(createHashHistory)({ queryKey: false })
645660

646661
## Utilities
647662

648-
### `match({ routes, location, [history], ...options }, cb)`
663+
### `match({ routes, location, [history], [...options] }, cb)`
649664

650665
This function is to be used for server-side rendering. It matches a set of routes to a location, without rendering, and calls a `callback(error, redirectLocation, renderProps)` when it's done.
651666

0 commit comments

Comments
 (0)