Skip to content

Commit fe9e2d1

Browse files
committed
Merge remote-tracking branch 'super/master'
2 parents 45df0dd + a50146d commit fe9e2d1

File tree

5 files changed

+54
-9
lines changed

5 files changed

+54
-9
lines changed

docs/Introduction.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,9 @@ render((
143143
), document.body)
144144
```
145145

146-
React Router knows how to build nested UI for us, so we don't have to manually figure out which `<Child>` component to render. Internally, the router converts your `<Route>` element hierarchy to a [route config](/docs/Glossary.md#routeconfig). But if you're not digging the JSX you can use plain objects instead:
146+
React Router knows how to build nested UI for us, so we don't have to manually figure out which `<Child>` component to render. For example, for a full path `/about` it would build `<App><About /></App>`.
147+
148+
Internally, the router converts your `<Route>` element hierarchy to a [route config](/docs/Glossary.md#routeconfig). But if you're not digging the JSX you can use plain objects instead:
147149

148150
```js
149151
const routes = {
@@ -195,7 +197,15 @@ render((
195197
), document.body)
196198
```
197199

198-
Now visits to URLs like `inbox/messages/Jkei3c32` will match the new route and nest the UI branch of `App -> Inbox -> Message`.
200+
Now visits to URLs like `inbox/messages/Jkei3c32` will match the new route and build this:
201+
202+
```
203+
<App>
204+
<Inbox>
205+
<Message params={ {id: 'Jkei3c32'} } />
206+
</Inbox>
207+
</App>
208+
```
199209

200210
### Getting URL Parameters
201211

docs/guides/advanced/DynamicRouting.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ const CourseRoute = {
3030

3131
getIndexRoute(location, callback) {
3232
require.ensure([], function (require) {
33-
callback(null, require('./components/Index'))
33+
callback(null, {
34+
component: require('./components/Index'),
35+
})
3436
})
3537
},
3638

docs/guides/basics/Histories.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ When a history transitions around your app with `pushState` or `replaceState`, i
3333

3434
The DOM API that hash history uses to transition around is simply `window.location.hash = newHash`, with no place to store location state. But, we want all histories to be able to use location state, so we shim it by creating a unique key for each location and then store that state in session storage. When the visitor clicks "back" and "forward" we now have a mechanism to restore the location state.
3535

36+
You can disable that feature (more [here](http://rackt.org/history/stable/HashHistoryCaveats.html)):
37+
```js
38+
// Opt-out of persistent state, not recommended.
39+
let history = createHistory({
40+
queryKey: false
41+
});
42+
```
43+
3644
### `createBrowserHistory`
3745
Browser history is the recommended history for browser application with React Router. It uses the [History](https://developer.mozilla.org/en-US/docs/Web/API/History) API built into the browser to manipulate the URL, creating real URLs that look like `example.com/some/path`.
3846

@@ -66,7 +74,7 @@ If you're using nginx, use the [`try_files` directive](http://nginx.org/en/docs/
6674
server {
6775
...
6876
location / {
69-
try_files $uri /index.html
77+
try_files $uri /index.html;
7078
}
7179
}
7280
```

modules/RoutingContext.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,13 @@ class RoutingContext extends Component {
2626

2727
static childContextTypes = {
2828
history: object.isRequired,
29-
location: object.isRequired
29+
location: object.isRequired,
30+
params: object.isRequired
3031
}
3132

3233
getChildContext() {
33-
return {
34-
history: this.props.history,
35-
location: this.props.location
36-
}
34+
const { history, location, params } = this.props
35+
return { history, location, params }
3736
}
3837

3938
createElement(component, props) {

modules/__tests__/RouteComponent-test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { render, unmountComponentAtNode } from 'react-dom'
55
import createHistory from 'history/lib/createMemoryHistory'
66
import Router from '../Router'
77

8+
const { object } = React.PropTypes
9+
810
describe('a Route Component', function () {
911

1012
let node
@@ -41,4 +43,28 @@ describe('a Route Component', function () {
4143
), node, done)
4244
})
4345

46+
it('receives the right context', function (done) {
47+
class RouteComponent extends Component {
48+
static contextTypes = {
49+
history: object.isRequired,
50+
location: object.isRequired,
51+
params: object.isRequired
52+
}
53+
componentDidMount() {
54+
expect(this.context.history).toEqual(this.props.history)
55+
expect(this.context.location).toEqual(this.props.location)
56+
expect(this.context.params).toEqual(this.props.params)
57+
}
58+
render() {
59+
return null
60+
}
61+
}
62+
63+
const route = { path: '/', component: RouteComponent }
64+
65+
render((
66+
<Router history={createHistory('/')} routes={route}/>
67+
), node, done)
68+
})
69+
4470
})

0 commit comments

Comments
 (0)