react-router 2.6.0 → 2.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGES.md +43 -0
- package/CODE_OF_CONDUCT.md +52 -29
- package/README.md +7 -7
- package/docs/API.md +48 -11
- package/docs/Glossary.md +3 -3
- package/docs/README.md +1 -0
- package/docs/guides/NavigatingOutsideOfComponents.md +12 -3
- package/docs/guides/README.md +13 -11
- package/docs/guides/{testing.md → Testing.md} +0 -0
- package/es6/Link.js +6 -1
- package/es6/PatternUtils.js +2 -2
- package/es6/applyRouterMiddleware.js +14 -10
- package/es6/createTransitionManager.js +2 -7
- package/es6/match.js +2 -1
- package/es6/withRouter.js +23 -2
- package/lib/Link.js +6 -1
- package/lib/PatternUtils.js +2 -2
- package/lib/applyRouterMiddleware.js +17 -10
- package/lib/createTransitionManager.js +3 -8
- package/lib/match.js +3 -1
- package/lib/withRouter.js +26 -2
- package/package.json +24 -27
- package/umd/ReactRouter.js +56 -54
- package/umd/ReactRouter.min.js +2 -2
package/CHANGES.md
CHANGED
|
@@ -1,3 +1,46 @@
|
|
|
1
|
+
## [v2.8.1]
|
|
2
|
+
> Sep 13, 2016
|
|
3
|
+
|
|
4
|
+
- **Bugfix:** Fix redirects that specify `query` ([#3808])
|
|
5
|
+
|
|
6
|
+
[v2.8.1]: https://github.com/reactjs/react-router/compare/v2.8.0...v2.8.1
|
|
7
|
+
[#3808]: https://github.com/reactjs/react-router/pull/3808
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
## [v2.8.0]
|
|
11
|
+
> Sep 9, 2016
|
|
12
|
+
|
|
13
|
+
- **Feature:** Support omitting `to` on `<Link>` ([#3803])
|
|
14
|
+
- **Refactor:** Use `history.replace` instead of `history.transitionTo` for redirects ([#3799])
|
|
15
|
+
|
|
16
|
+
[v2.8.0]: https://github.com/reactjs/react-router/compare/v2.7.0...v2.8.0
|
|
17
|
+
[#3799]: https://github.com/reactjs/react-router/pull/3799
|
|
18
|
+
[#3803]: https://github.com/reactjs/react-router/pull/3803
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
## [v2.7.0]
|
|
22
|
+
> Aug 20, 2016
|
|
23
|
+
|
|
24
|
+
- **Feature:** Support `router` as a prop on `withRouter`-wrapped components for overriding the router object from context ([#3729])
|
|
25
|
+
- **Feature:** Add `withRef` option to `withRouter` that enables `getWrappedInstance` ([#3735], [#3740])
|
|
26
|
+
- **Bugfix:** Warn on invalid router middlewares ([#3717])
|
|
27
|
+
|
|
28
|
+
[v2.7.0]: https://github.com/reactjs/react-router/compare/v2.6.1...v2.7.0
|
|
29
|
+
[#3717]: https://github.com/reactjs/react-router/pull/3717
|
|
30
|
+
[#3729]: https://github.com/reactjs/react-router/pull/3729
|
|
31
|
+
[#3735]: https://github.com/reactjs/react-router/pull/3735
|
|
32
|
+
[#3740]: https://github.com/reactjs/react-router/pull/3740
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
## [v2.6.1]
|
|
36
|
+
> Jul 29, 2016
|
|
37
|
+
|
|
38
|
+
- **Bugfix:** Correctly handle routes with patterns that are the names of properties on `Object.prototype` ([#3680])
|
|
39
|
+
|
|
40
|
+
[v2.6.1]: https://github.com/reactjs/react-router/compare/v2.6.0...v2.6.1
|
|
41
|
+
[#3680]: https://github.com/reactjs/react-router/pull/3680
|
|
42
|
+
|
|
43
|
+
|
|
1
44
|
## [v2.6.0]
|
|
2
45
|
> Jul 18, 2016
|
|
3
46
|
|
package/CODE_OF_CONDUCT.md
CHANGED
|
@@ -1,24 +1,41 @@
|
|
|
1
|
-
# Contributor Code of Conduct
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
fostering an open and welcoming community, we pledge to respect all people who
|
|
5
|
-
contribute through reporting issues, posting feature requests, updating
|
|
6
|
-
documentation, submitting pull requests or patches, and other activities.
|
|
3
|
+
## Our Pledge
|
|
7
4
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
|
10
|
+
orientation.
|
|
11
|
+
|
|
12
|
+
## Our Standards
|
|
13
|
+
|
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
|
15
|
+
include:
|
|
16
|
+
|
|
17
|
+
* Using welcoming and inclusive language
|
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
|
19
|
+
* Gracefully accepting constructive criticism
|
|
20
|
+
* Focusing on what is best for the community
|
|
21
|
+
* Showing empathy towards other community members
|
|
12
22
|
|
|
13
23
|
Examples of unacceptable behavior by participants include:
|
|
14
24
|
|
|
15
|
-
* The use of sexualized language or imagery
|
|
16
|
-
|
|
17
|
-
* Trolling
|
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
26
|
+
advances
|
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
18
28
|
* Public or private harassment
|
|
19
|
-
* Publishing
|
|
20
|
-
|
|
21
|
-
* Other
|
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
|
30
|
+
address, without explicit permission
|
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
32
|
+
professional setting
|
|
33
|
+
|
|
34
|
+
## Our Responsibilities
|
|
35
|
+
|
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
|
38
|
+
response to any instances of unacceptable behavior.
|
|
22
39
|
|
|
23
40
|
Project maintainers have the right and responsibility to remove, edit, or
|
|
24
41
|
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
@@ -26,26 +43,32 @@ that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
|
26
43
|
permanently any contributor for other behaviors that they deem inappropriate,
|
|
27
44
|
threatening, offensive, or harmful.
|
|
28
45
|
|
|
29
|
-
|
|
30
|
-
fairly and consistently applying these principles to every aspect of managing
|
|
31
|
-
this project. Project maintainers who do not follow or enforce the Code of
|
|
32
|
-
Conduct may be permanently removed from the project team.
|
|
46
|
+
## Scope
|
|
33
47
|
|
|
34
48
|
This Code of Conduct applies both within project spaces and in public spaces
|
|
35
|
-
when an individual is representing the project or its community.
|
|
49
|
+
when an individual is representing the project or its community. Examples of
|
|
50
|
+
representing a project or community include using an official project e-mail
|
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
|
53
|
+
further defined and clarified by project maintainers.
|
|
54
|
+
|
|
55
|
+
## Enforcement
|
|
36
56
|
|
|
37
57
|
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
38
|
-
reported by contacting
|
|
58
|
+
reported by contacting the project team at rpflorence@gmail.com. All
|
|
39
59
|
complaints will be reviewed and investigated and will result in a response that
|
|
40
|
-
is deemed necessary and appropriate to the circumstances.
|
|
41
|
-
obligated to maintain confidentiality with regard to the reporter of an
|
|
42
|
-
|
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
|
43
63
|
|
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
|
66
|
+
members of the project's leadership.
|
|
44
67
|
|
|
45
|
-
|
|
46
|
-
version 1.3.0, available at
|
|
47
|
-
[http://contributor-covenant.org/version/1/3/0/][version]
|
|
68
|
+
## Attribution
|
|
48
69
|
|
|
49
|
-
[homepage]
|
|
50
|
-
[
|
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
|
51
72
|
|
|
73
|
+
[homepage]: http://contributor-covenant.org
|
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ React Router is a complete routing library for [React](https://facebook.github.i
|
|
|
6
6
|
|
|
7
7
|
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.
|
|
8
8
|
|
|
9
|
-
[![
|
|
9
|
+
[![Codecov][codecov-badge]][codecov]
|
|
10
10
|
[![Discord][discord-badge]][discord]
|
|
11
11
|
|
|
12
12
|
### Docs & Help
|
|
@@ -20,7 +20,7 @@ React Router keeps your UI in sync with the URL. It has a simple API with powerf
|
|
|
20
20
|
|
|
21
21
|
**Older Versions:**
|
|
22
22
|
|
|
23
|
-
- 0.13.x - [docs](https://github.com/reactjs/react-router/tree/
|
|
23
|
+
- 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)
|
|
24
24
|
- 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
25
|
|
|
26
26
|
For questions and support, please visit [our channel on Reactiflux](https://discord.gg/0ZcbPKXt5bYaNQ46) or [Stack Overflow](http://stackoverflow.com/questions/tagged/react-router).
|
|
@@ -47,10 +47,10 @@ var Route = require('react-router').Route
|
|
|
47
47
|
var Link = require('react-router').Link
|
|
48
48
|
```
|
|
49
49
|
|
|
50
|
-
The UMD build is also available on [
|
|
50
|
+
The UMD build is also available on [unpkg](https://unpkg.com):
|
|
51
51
|
|
|
52
52
|
```html
|
|
53
|
-
<script src="https://
|
|
53
|
+
<script src="https://unpkg.com/react-router/umd/ReactRouter.min.js"></script>
|
|
54
54
|
```
|
|
55
55
|
|
|
56
56
|
You can find the library on `window.ReactRouter`.
|
|
@@ -125,7 +125,7 @@ See more in the [Introduction](/docs/Introduction.md), [Guides](/docs/guides/REA
|
|
|
125
125
|
|
|
126
126
|
### Versioning and Stability
|
|
127
127
|
|
|
128
|
-
We want React Router to be a stable dependency that’s easy to keep current. We
|
|
128
|
+
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).
|
|
129
129
|
|
|
130
130
|
### Thanks
|
|
131
131
|
|
|
@@ -142,8 +142,8 @@ Also, thanks to [BrowserStack](https://www.browserstack.com/) for providing the
|
|
|
142
142
|
[npm-badge]: https://img.shields.io/npm/v/react-router.svg?style=flat-square
|
|
143
143
|
[npm]: https://www.npmjs.org/package/react-router
|
|
144
144
|
|
|
145
|
-
[
|
|
146
|
-
[
|
|
145
|
+
[codecov-badge]: https://img.shields.io/codecov/c/github/reactjs/react-router/master.svg?style=flat-square
|
|
146
|
+
[codecov]: https://codecov.io/gh/reactjs/react-router
|
|
147
147
|
|
|
148
148
|
[discord-badge]: https://img.shields.io/badge/Discord-join%20chat%20%E2%86%92-738bd7.svg?style=flat-square
|
|
149
149
|
[discord]: https://discord.gg/0ZcbPKXt5bYaNQ46
|
package/docs/API.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
- [`<Router>`](#router)
|
|
5
5
|
- [`<Link>`](#link)
|
|
6
6
|
- [`<IndexLink>`](#indexlink)
|
|
7
|
-
- [`withRouter`](#withroutercomponent)
|
|
7
|
+
- [`withRouter`](#withroutercomponent-options)
|
|
8
8
|
- [`<RouterContext>`](#routercontext)
|
|
9
9
|
- [`context.router`](#contextrouter)
|
|
10
10
|
- `<RoutingContext>` (deprecated, use `<RouterContext>`)
|
|
@@ -105,7 +105,7 @@ A `<Link>` can know when the route it links to is active and automatically apply
|
|
|
105
105
|
|
|
106
106
|
#### Props
|
|
107
107
|
##### `to`
|
|
108
|
-
A [location descriptor](https://github.com/
|
|
108
|
+
A [location descriptor](https://github.com/reactjs/react-router/blob/master/docs/Glossary.md#locationdescriptor). Usually this is a string or an object, with the following semantics:
|
|
109
109
|
|
|
110
110
|
* If it's a string it represents the absolute path to link to, e.g. `/users/123` (relative paths are not supported).
|
|
111
111
|
* If it's an object it can have four keys:
|
|
@@ -113,6 +113,7 @@ A [location descriptor](https://github.com/ReactTraining/history/blob/master/doc
|
|
|
113
113
|
* `query`: An object of key:value pairs to be stringified.
|
|
114
114
|
* `hash`: A hash to put in the URL, e.g. `#a-hash`.
|
|
115
115
|
* `state`: State to persist to the `location`.
|
|
116
|
+
* If it is not specified, an anchor tag without an `href` attribute will be rendered.
|
|
116
117
|
|
|
117
118
|
_Note: React Router currently does not manage scroll position, and will not scroll to the element corresponding to `hash`._
|
|
118
119
|
|
|
@@ -157,8 +158,22 @@ Given a route like `<Route path="/users/:userId" />`:
|
|
|
157
158
|
### `<IndexLink>`
|
|
158
159
|
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.
|
|
159
160
|
|
|
160
|
-
### `withRouter(
|
|
161
|
-
A HoC (higher-order component) that wraps another component to provide `
|
|
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
|
+
```
|
|
162
177
|
|
|
163
178
|
### `<RouterContext>`
|
|
164
179
|
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.
|
|
@@ -244,7 +259,7 @@ be rendered by the parent route component with `this.props.children`.
|
|
|
244
259
|
|
|
245
260
|
```js
|
|
246
261
|
const routes = (
|
|
247
|
-
<Route component={App}>
|
|
262
|
+
<Route path="/" component={App}>
|
|
248
263
|
<Route path="groups" component={Groups} />
|
|
249
264
|
<Route path="users" component={Users} />
|
|
250
265
|
</Route>
|
|
@@ -271,7 +286,7 @@ Routes can define one or more named components as an object of `[name]: componen
|
|
|
271
286
|
// <App main={<Users />} sidebar={<UsersSidebar />} />
|
|
272
287
|
|
|
273
288
|
const routes = (
|
|
274
|
-
<Route component={App}>
|
|
289
|
+
<Route path="/" component={App}>
|
|
275
290
|
<Route path="groups" components={{main: Groups, sidebar: GroupsSidebar}} />
|
|
276
291
|
<Route path="users" components={{main: Users, sidebar: UsersSidebar}}>
|
|
277
292
|
<Route path=":userId" component={Profile} />
|
|
@@ -345,6 +360,28 @@ Called when a route is about to be entered. It provides the next router state an
|
|
|
345
360
|
|
|
346
361
|
If `callback` is listed as a 3rd argument, this hook will run asynchronously, and the transition will block until `callback` is called.
|
|
347
362
|
|
|
363
|
+
###### `callback` signature
|
|
364
|
+
`cb(err)`
|
|
365
|
+
|
|
366
|
+
```js
|
|
367
|
+
const userIsInATeam = (nextState, replace, callback) => {
|
|
368
|
+
fetch(...)
|
|
369
|
+
.then(response = response.json())
|
|
370
|
+
.then(userTeams => {
|
|
371
|
+
if (userTeams.length === 0) {
|
|
372
|
+
replace(`/users/${nextState.params.userId}/teams/new`)
|
|
373
|
+
}
|
|
374
|
+
callback();
|
|
375
|
+
})
|
|
376
|
+
.catch(error => {
|
|
377
|
+
// do some error handling here
|
|
378
|
+
callback(error);
|
|
379
|
+
})
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
<Route path="/users/:userId/teams" onEnter={userIsInATeam} />
|
|
383
|
+
```
|
|
384
|
+
|
|
348
385
|
##### `onChange(prevState, nextState, replace, callback?)`
|
|
349
386
|
Called on routes when the location changes, but the route itself neither enters or leaves. For example, this will be called when a route's children change, or when the location query changes. It provides the previous router state, the next router state, and a function to redirect to another path. `this` will be the route instance that triggered the hook.
|
|
350
387
|
|
|
@@ -498,7 +535,7 @@ A route's component is rendered when that route matches the URL. The router will
|
|
|
498
535
|
### Injected Props
|
|
499
536
|
|
|
500
537
|
#### `location`
|
|
501
|
-
The current [location](https://github.com/
|
|
538
|
+
The current [location](https://github.com/mjackson/history/blob/v2.x/docs/Location.md).
|
|
502
539
|
|
|
503
540
|
#### `params`
|
|
504
541
|
The dynamic segments of the URL.
|
|
@@ -507,7 +544,7 @@ The dynamic segments of the URL.
|
|
|
507
544
|
The route that rendered this component.
|
|
508
545
|
|
|
509
546
|
#### `routeParams`
|
|
510
|
-
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}`.
|
|
547
|
+
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'}`.
|
|
511
548
|
|
|
512
549
|
#### `children`
|
|
513
550
|
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`.
|
|
@@ -599,8 +636,8 @@ For more details, please see the [histories guide](/docs/guides/Histories.md).
|
|
|
599
636
|
`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`.
|
|
600
637
|
|
|
601
638
|
|
|
602
|
-
### `createMemoryHistory(options)`
|
|
603
|
-
`createMemoryHistory` creates an in-memory `history` object that does not interact with the browser URL. This is useful when you need to customize the `history` used for server-side rendering,
|
|
639
|
+
### `createMemoryHistory([options])`
|
|
640
|
+
`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>`.
|
|
604
641
|
|
|
605
642
|
|
|
606
643
|
### `useRouterHistory(createHistory)`
|
|
@@ -622,7 +659,7 @@ const history = useRouterHistory(createHashHistory)({ queryKey: false })
|
|
|
622
659
|
|
|
623
660
|
## Utilities
|
|
624
661
|
|
|
625
|
-
### `match({ routes, location, [history], ...options }, cb)`
|
|
662
|
+
### `match({ routes, location, [history], [...options] }, cb)`
|
|
626
663
|
|
|
627
664
|
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.
|
|
628
665
|
|
package/docs/Glossary.md
CHANGED
|
@@ -69,7 +69,7 @@ A *hash* is a string that represents the hash portion of the URL. It is synonymo
|
|
|
69
69
|
type LeaveHook = (prevState: RouterState) => any;
|
|
70
70
|
```
|
|
71
71
|
|
|
72
|
-
A *leave hook* is a user-defined function that is called when a route is about to be unmounted. It receives the previous [router state](#routerstate) as its first argument.
|
|
72
|
+
A *leave hook* is a user-defined function that is called when a route is about to be unmounted. It receives the previous [router state](#routerstate) as its first argument.
|
|
73
73
|
|
|
74
74
|
## Location
|
|
75
75
|
|
|
@@ -89,7 +89,7 @@ A *location* answers two important (philosophical) questions:
|
|
|
89
89
|
- Where am I?
|
|
90
90
|
- How did I get here?
|
|
91
91
|
|
|
92
|
-
New locations are typically created each time the URL changes. You can read more about locations in [the `history` docs](https://github.com/
|
|
92
|
+
New locations are typically created each time the URL changes. You can read more about locations in [the `history` docs](https://github.com/mjackson/history/blob/v2.x/docs/Location.md).
|
|
93
93
|
|
|
94
94
|
### LocationDescriptor
|
|
95
95
|
|
|
@@ -104,7 +104,7 @@ New locations are typically created each time the URL changes. You can read more
|
|
|
104
104
|
|
|
105
105
|
A *location descriptor* is the pushable analogue of a location. Locations tell you where you are; you create location descriptors to say where to go.
|
|
106
106
|
|
|
107
|
-
You can read more about location descriptors in [the `history` docs](https://github.com/
|
|
107
|
+
You can read more about location descriptors in [the `history` docs](https://github.com/mjackson/history/blob/v2.x/docs/Location.md).
|
|
108
108
|
|
|
109
109
|
## LocationKey
|
|
110
110
|
|
package/docs/README.md
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* [Histories](guides/Histories.md)
|
|
9
9
|
* [Index Routes and Links](guides/IndexRoutes.md)
|
|
10
10
|
* Advanced Usage
|
|
11
|
+
* [Testing](guides/Testing.md)
|
|
11
12
|
* [Dynamic Routing](guides/DynamicRouting.md)
|
|
12
13
|
* [Confirming Navigation](guides/ConfirmingNavigation.md)
|
|
13
14
|
* [Server Rendering](guides/ServerRendering.md)
|
|
@@ -3,14 +3,23 @@
|
|
|
3
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`.
|
|
4
4
|
|
|
5
5
|
```js
|
|
6
|
-
//
|
|
6
|
+
// Your main file that renders a <Router>:
|
|
7
7
|
import { Router, browserHistory } from 'react-router'
|
|
8
8
|
import routes from './app/routes'
|
|
9
|
-
|
|
9
|
+
|
|
10
|
+
render(
|
|
11
|
+
<Router history={browserHistory} routes={routes} />,
|
|
12
|
+
mountNode
|
|
13
|
+
)
|
|
10
14
|
```
|
|
11
15
|
|
|
12
16
|
```js
|
|
13
|
-
//
|
|
17
|
+
// Somewhere like a Redux middleware or Flux action:
|
|
14
18
|
import { browserHistory } from 'react-router'
|
|
19
|
+
|
|
20
|
+
// Go to /some/path.
|
|
15
21
|
browserHistory.push('/some/path')
|
|
22
|
+
|
|
23
|
+
// Go back to previous location.
|
|
24
|
+
browserHistory.goBack()
|
|
16
25
|
```
|
package/docs/guides/README.md
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
# Guides
|
|
2
2
|
|
|
3
|
-
*
|
|
4
|
-
* [Route
|
|
5
|
-
* [
|
|
6
|
-
* [
|
|
7
|
-
* [
|
|
8
|
-
*
|
|
9
|
-
* [
|
|
10
|
-
* [
|
|
11
|
-
* [
|
|
12
|
-
* [
|
|
13
|
-
* [
|
|
3
|
+
* Basics
|
|
4
|
+
* [Route Configuration](RouteConfiguration.md)
|
|
5
|
+
* [Route Matching](RouteMatching.md)
|
|
6
|
+
* [Histories](Histories.md)
|
|
7
|
+
* [Index Routes and Links](IndexRoutes.md)
|
|
8
|
+
* Advanced Usage
|
|
9
|
+
* [Testing](Testing.md)
|
|
10
|
+
* [Dynamic Routing](DynamicRouting.md)
|
|
11
|
+
* [Confirming Navigation](ConfirmingNavigation.md)
|
|
12
|
+
* [Server Rendering](ServerRendering.md)
|
|
13
|
+
* [Component Lifecycle](ComponentLifecycle.md)
|
|
14
|
+
* [Navigating Outside of Components](NavigatingOutsideOfComponents.md)
|
|
15
|
+
* [Minimizing Bundle Size](MinimizingBundleSize.md)
|
|
File without changes
|
package/es6/Link.js
CHANGED
|
@@ -69,7 +69,7 @@ var Link = React.createClass({
|
|
|
69
69
|
},
|
|
70
70
|
|
|
71
71
|
propTypes: {
|
|
72
|
-
to: oneOfType([string, object])
|
|
72
|
+
to: oneOfType([string, object]),
|
|
73
73
|
query: object,
|
|
74
74
|
hash: string,
|
|
75
75
|
state: object,
|
|
@@ -130,6 +130,11 @@ var Link = React.createClass({
|
|
|
130
130
|
|
|
131
131
|
|
|
132
132
|
if (router) {
|
|
133
|
+
// If user does not specify a `to` prop, return an empty anchor tag.
|
|
134
|
+
if (to == null) {
|
|
135
|
+
return React.createElement('a', props);
|
|
136
|
+
}
|
|
137
|
+
|
|
133
138
|
var location = createLocationDescriptor(to, { query: query, hash: hash, state: state });
|
|
134
139
|
props.href = router.createHref(location);
|
|
135
140
|
|
package/es6/PatternUtils.js
CHANGED
|
@@ -51,10 +51,10 @@ function _compilePattern(pattern) {
|
|
|
51
51
|
};
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
var CompiledPatternsCache =
|
|
54
|
+
var CompiledPatternsCache = Object.create(null);
|
|
55
55
|
|
|
56
56
|
export function compilePattern(pattern) {
|
|
57
|
-
if (!
|
|
57
|
+
if (!CompiledPatternsCache[pattern]) CompiledPatternsCache[pattern] = _compilePattern(pattern);
|
|
58
58
|
|
|
59
59
|
return CompiledPatternsCache[pattern];
|
|
60
60
|
}
|
|
@@ -2,22 +2,26 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < argument
|
|
|
2
2
|
|
|
3
3
|
import React, { createElement } from 'react';
|
|
4
4
|
import RouterContext from './RouterContext';
|
|
5
|
+
import warning from './routerWarning';
|
|
5
6
|
|
|
6
7
|
export default (function () {
|
|
7
8
|
for (var _len = arguments.length, middlewares = Array(_len), _key = 0; _key < _len; _key++) {
|
|
8
9
|
middlewares[_key] = arguments[_key];
|
|
9
10
|
}
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
12
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
13
|
+
middlewares.forEach(function (middleware, index) {
|
|
14
|
+
process.env.NODE_ENV !== 'production' ? warning(middleware.renderRouterContext || middleware.renderRouteComponent, 'The middleware specified at index ' + index + ' does not appear to be ' + 'a valid React Router middleware.') : void 0;
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
var withContext = middlewares.map(function (middleware) {
|
|
19
|
+
return middleware.renderRouterContext;
|
|
20
|
+
}).filter(Boolean);
|
|
21
|
+
var withComponent = middlewares.map(function (middleware) {
|
|
22
|
+
return middleware.renderRouteComponent;
|
|
23
|
+
}).filter(Boolean);
|
|
24
|
+
|
|
21
25
|
var makeCreateElement = function makeCreateElement() {
|
|
22
26
|
var baseCreateElement = arguments.length <= 0 || arguments[0] === undefined ? createElement : arguments[0];
|
|
23
27
|
return function (Component, props) {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
|
|
2
2
|
|
|
3
3
|
import warning from './routerWarning';
|
|
4
|
-
import { REPLACE } from 'history/lib/Actions';
|
|
5
4
|
import computeChangedRoutes from './computeChangedRoutes';
|
|
6
5
|
import { runEnterHooks, runChangeHooks, runLeaveHooks } from './TransitionUtils';
|
|
7
6
|
import _isActive from './isActive';
|
|
@@ -36,10 +35,6 @@ export default function createTransitionManager(history, routes) {
|
|
|
36
35
|
return _isActive(location, indexOnly, state.location, state.routes, state.params);
|
|
37
36
|
}
|
|
38
37
|
|
|
39
|
-
function createLocationFromRedirectInfo(location) {
|
|
40
|
-
return history.createLocation(location, REPLACE);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
38
|
var partialNextState = void 0;
|
|
44
39
|
|
|
45
40
|
function match(location, callback) {
|
|
@@ -97,7 +92,7 @@ export default function createTransitionManager(history, routes) {
|
|
|
97
92
|
}
|
|
98
93
|
|
|
99
94
|
function handleErrorOrRedirect(error, redirectInfo) {
|
|
100
|
-
if (error) callback(error);else callback(null,
|
|
95
|
+
if (error) callback(error);else callback(null, redirectInfo);
|
|
101
96
|
}
|
|
102
97
|
}
|
|
103
98
|
|
|
@@ -260,7 +255,7 @@ export default function createTransitionManager(history, routes) {
|
|
|
260
255
|
if (error) {
|
|
261
256
|
listener(error);
|
|
262
257
|
} else if (redirectLocation) {
|
|
263
|
-
history.
|
|
258
|
+
history.replace(redirectLocation);
|
|
264
259
|
} else if (nextState) {
|
|
265
260
|
listener(null, nextState);
|
|
266
261
|
} else {
|
package/es6/match.js
CHANGED
|
@@ -2,6 +2,7 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < argument
|
|
|
2
2
|
|
|
3
3
|
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
|
|
4
4
|
|
|
5
|
+
import { REPLACE } from 'history/lib/Actions';
|
|
5
6
|
import invariant from 'invariant';
|
|
6
7
|
|
|
7
8
|
import createMemoryHistory from './createMemoryHistory';
|
|
@@ -47,7 +48,7 @@ function match(_ref, callback) {
|
|
|
47
48
|
history = createRoutingHistory(history, transitionManager);
|
|
48
49
|
|
|
49
50
|
transitionManager.match(location, function (error, redirectLocation, nextState) {
|
|
50
|
-
callback(error, redirectLocation, nextState && _extends({}, nextState, {
|
|
51
|
+
callback(error, redirectLocation && router.createLocation(redirectLocation, REPLACE), nextState && _extends({}, nextState, {
|
|
51
52
|
history: history,
|
|
52
53
|
router: router,
|
|
53
54
|
matchContext: { history: history, transitionManager: transitionManager, router: router }
|
package/es6/withRouter.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
|
|
2
2
|
|
|
3
|
+
import invariant from 'invariant';
|
|
3
4
|
import React from 'react';
|
|
4
5
|
import hoistStatics from 'hoist-non-react-statics';
|
|
5
6
|
import { routerShape } from './PropTypes';
|
|
@@ -8,13 +9,33 @@ function getDisplayName(WrappedComponent) {
|
|
|
8
9
|
return WrappedComponent.displayName || WrappedComponent.name || 'Component';
|
|
9
10
|
}
|
|
10
11
|
|
|
11
|
-
export default function withRouter(WrappedComponent) {
|
|
12
|
+
export default function withRouter(WrappedComponent, options) {
|
|
13
|
+
var withRef = options && options.withRef;
|
|
14
|
+
|
|
12
15
|
var WithRouter = React.createClass({
|
|
13
16
|
displayName: 'WithRouter',
|
|
14
17
|
|
|
15
18
|
contextTypes: { router: routerShape },
|
|
19
|
+
propTypes: { router: routerShape },
|
|
20
|
+
|
|
21
|
+
getWrappedInstance: function getWrappedInstance() {
|
|
22
|
+
!withRef ? process.env.NODE_ENV !== 'production' ? invariant(false, 'To access the wrapped instance, you need to specify ' + '`{ withRef: true }` as the second argument of the withRouter() call.') : invariant(false) : void 0;
|
|
23
|
+
|
|
24
|
+
return this.wrappedInstance;
|
|
25
|
+
},
|
|
16
26
|
render: function render() {
|
|
17
|
-
|
|
27
|
+
var _this = this;
|
|
28
|
+
|
|
29
|
+
var router = this.props.router || this.context.router;
|
|
30
|
+
var props = _extends({}, this.props, { router: router });
|
|
31
|
+
|
|
32
|
+
if (withRef) {
|
|
33
|
+
props.ref = function (c) {
|
|
34
|
+
_this.wrappedInstance = c;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return React.createElement(WrappedComponent, props);
|
|
18
39
|
}
|
|
19
40
|
});
|
|
20
41
|
|
package/lib/Link.js
CHANGED
|
@@ -84,7 +84,7 @@ var Link = _react2.default.createClass({
|
|
|
84
84
|
},
|
|
85
85
|
|
|
86
86
|
propTypes: {
|
|
87
|
-
to: oneOfType([string, object])
|
|
87
|
+
to: oneOfType([string, object]),
|
|
88
88
|
query: object,
|
|
89
89
|
hash: string,
|
|
90
90
|
state: object,
|
|
@@ -145,6 +145,11 @@ var Link = _react2.default.createClass({
|
|
|
145
145
|
|
|
146
146
|
|
|
147
147
|
if (router) {
|
|
148
|
+
// If user does not specify a `to` prop, return an empty anchor tag.
|
|
149
|
+
if (to == null) {
|
|
150
|
+
return _react2.default.createElement('a', props);
|
|
151
|
+
}
|
|
152
|
+
|
|
148
153
|
var location = createLocationDescriptor(to, { query: query, hash: hash, state: state });
|
|
149
154
|
props.href = router.createHref(location);
|
|
150
155
|
|
package/lib/PatternUtils.js
CHANGED
|
@@ -64,10 +64,10 @@ function _compilePattern(pattern) {
|
|
|
64
64
|
};
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
var CompiledPatternsCache =
|
|
67
|
+
var CompiledPatternsCache = Object.create(null);
|
|
68
68
|
|
|
69
69
|
function compilePattern(pattern) {
|
|
70
|
-
if (!
|
|
70
|
+
if (!CompiledPatternsCache[pattern]) CompiledPatternsCache[pattern] = _compilePattern(pattern);
|
|
71
71
|
|
|
72
72
|
return CompiledPatternsCache[pattern];
|
|
73
73
|
}
|