Skip to content

Commit acfe0cc

Browse files
committed
add router to route component props
(maybe we don’t want this?)
1 parent 3aa2115 commit acfe0cc

File tree

4 files changed

+10
-19
lines changed

4 files changed

+10
-19
lines changed

examples/master-detail/app.js

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
import React from 'react'
22
import { render, findDOMNode } from 'react-dom'
3-
import { createHistory, useBasename } from 'history'
4-
import { Router, History, Route, IndexRoute, Link } from 'react-router'
3+
import { browserHistory, Router, Route, IndexRoute, Link } from 'react-router'
54
import ContactStore from './ContactStore'
6-
7-
require('./app.css')
8-
9-
const history = useBasename(createHistory)({
10-
basename: '/master-detail'
11-
})
5+
import './app.css'
126

137
const App = React.createClass({
148
getInitialState() {
@@ -68,7 +62,6 @@ const Index = React.createClass({
6862
})
6963

7064
const Contact = React.createClass({
71-
mixins: [ History ],
7265

7366
getStateFromStore(props) {
7467
const { id } = props ? props.params : this.props.params
@@ -104,7 +97,7 @@ const Contact = React.createClass({
10497
destroy() {
10598
const { id } = this.props.params
10699
ContactStore.removeContact(id)
107-
this.history.push('/')
100+
this.props.router.push('/')
108101
},
109102

110103
render() {
@@ -123,7 +116,6 @@ const Contact = React.createClass({
123116
})
124117

125118
const NewContact = React.createClass({
126-
mixins: [ History ],
127119

128120
createContact(event) {
129121
event.preventDefault()
@@ -132,7 +124,7 @@ const NewContact = React.createClass({
132124
first: findDOMNode(this.refs.first).value,
133125
last: findDOMNode(this.refs.last).value
134126
}, (contact) => {
135-
this.history.push(`/contact/${contact.id}`)
127+
this.props.router.push(`/contact/${contact.id}`)
136128
})
137129
},
138130

@@ -158,7 +150,7 @@ const NotFound = React.createClass({
158150
})
159151

160152
render((
161-
<Router history={history}>
153+
<Router history={browserHistory}>
162154
<Route path="/" component={App}>
163155
<IndexRoute component={Index} />
164156
<Route path="contact/new" component={NewContact} />

examples/master-detail/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<!doctype html public "embarassment">
22
<title>Master Detail Example</title>
3+
<base href="/master-detail"/>
34
<link href="/global.css" rel="stylesheet"/>
45
<body>
56
<h1 class="breadcrumbs"><a href="/">React Router Examples</a> / Master Detail</h1>

modules/RouterContext.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,7 @@ const RouterContext = React.createClass({
3939
getChildContext() {
4040
let { router, history, location } = this.props
4141
if (!router) {
42-
warning(
43-
false,
44-
'`<RouterContext>` expects a `router` rather than a `history`'
45-
)
42+
warning(false, '`<RouterContext>` expects a `router` rather than a `history`')
4643

4744
router = {
4845
...history,
@@ -63,7 +60,7 @@ const RouterContext = React.createClass({
6360
},
6461

6562
render() {
66-
const { history, location, routes, params, components } = this.props
63+
const { router, history, location, routes, params, components } = this.props
6764
let element = null
6865

6966
if (components) {
@@ -74,6 +71,7 @@ const RouterContext = React.createClass({
7471
const route = routes[index]
7572
const routeParams = getRouteParams(route, params)
7673
const props = {
74+
router,
7775
history,
7876
location,
7977
params,

modules/RouterUtils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export function createRoutingHistory(history, transitionManager) {
1818
if (__DEV__) {
1919
history = deprecateObjectProperties(
2020
history,
21-
'routing history is deprecated; use the `router` object instead'
21+
'`props.history` and `context.history` are deprecated; use `props.router` on route components and `context.router` on deeper components.'
2222
)
2323
}
2424

0 commit comments

Comments
 (0)