Skip to content

Use react-router-redux@4 #1414

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions examples/real-world/containers/App.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { Component, PropTypes } from 'react'
import { connect } from 'react-redux'
import { push } from 'react-router-redux'
import { browserHistory } from 'react-router'
import Explore from '../components/Explore'
import { resetErrorMessage } from '../actions'

Expand All @@ -17,7 +17,7 @@ class App extends Component {
}

handleChange(nextValue) {
this.props.push(`/${nextValue}`)
browserHistory.push(`/${nextValue}`)
}

renderErrorMessage() {
Expand Down Expand Up @@ -56,20 +56,18 @@ App.propTypes = {
// Injected by React Redux
errorMessage: PropTypes.string,
resetErrorMessage: PropTypes.func.isRequired,
push: PropTypes.func.isRequired,
inputValue: PropTypes.string.isRequired,
// Injected by React Router
children: PropTypes.node
}

function mapStateToProps(state) {
function mapStateToProps(state, ownProps) {
return {
errorMessage: state.errorMessage,
inputValue: state.routing.location.pathname.substring(1)
inputValue: ownProps.location.pathname.substring(1)
}
}

export default connect(mapStateToProps, {
resetErrorMessage,
push
resetErrorMessage
})(App)
4 changes: 2 additions & 2 deletions examples/real-world/containers/RepoPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ RepoPage.propTypes = {
loadStargazers: PropTypes.func.isRequired
}

function mapStateToProps(state, props) {
const { login, name } = props.params
function mapStateToProps(state, ownProps) {
const { login, name } = ownProps.params
const {
pagination: { stargazersByRepo },
entities: { users, repos }
Expand Down
6 changes: 3 additions & 3 deletions examples/real-world/containers/Root.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import React, { Component, PropTypes } from 'react'
import { Provider } from 'react-redux'
import routes from '../routes'
import DevTools from './DevTools'
import { Router, browserHistory } from 'react-router'
import { Router } from 'react-router'

export default class Root extends Component {
render() {
const { store } = this.props
const { store, history } = this.props
return (
<Provider store={store}>
<div>
<Router history={browserHistory} routes={routes} />
<Router history={history} routes={routes} />
<DevTools />
</div>
</Provider>
Expand Down
6 changes: 3 additions & 3 deletions examples/real-world/containers/Root.prod.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React, { Component, PropTypes } from 'react'
import { Provider } from 'react-redux'
import routes from '../routes'
import { Router, browserHistory } from 'react-router'
import { Router } from 'react-router'

export default class Root extends Component {
render() {
const { store } = this.props
const { store, history } = this.props
return (
<Provider store={store}>
<Router history={browserHistory} routes={routes} />
<Router history={history} routes={routes} />
</Provider>
)
}
Expand Down
4 changes: 2 additions & 2 deletions examples/real-world/containers/UserPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ UserPage.propTypes = {
loadStarred: PropTypes.func.isRequired
}

function mapStateToProps(state, props) {
const { login } = props.params
function mapStateToProps(state, ownProps) {
const { login } = ownProps.params
const {
pagination: { starredByUser },
entities: { users, repos }
Expand Down
5 changes: 4 additions & 1 deletion examples/real-world/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import 'babel-polyfill'
import React from 'react'
import { render } from 'react-dom'
import { browserHistory } from 'react-router'
import { syncHistoryWithStore } from 'react-router-redux'
import Root from './containers/Root'
import configureStore from './store/configureStore'

const store = configureStore()
const history = syncHistoryWithStore(browserHistory, store)

render(
<Root store={store} />,
<Root store={store} history={history} />,
document.getElementById('root')
)
4 changes: 2 additions & 2 deletions examples/real-world/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"react": "^0.14.7",
"react-dom": "^0.14.7",
"react-redux": "^4.2.1",
"react-router": "2.0.0-rc5",
"react-router-redux": "^2.1.0",
"react-router": "2.0.0",
"react-router-redux": "^4.0.0-rc.1",
"redux": "^3.2.1",
"redux-logger": "^2.4.0",
"redux-thunk": "^1.0.3"
Expand Down
5 changes: 2 additions & 3 deletions examples/real-world/reducers/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as ActionTypes from '../actions'
import merge from 'lodash/merge'
import paginate from './paginate'
import { routeReducer } from 'react-router-redux'
import { routerReducer as routing } from 'react-router-redux'
import { combineReducers } from 'redux'

// Updates an entity cache in response to any action with response.entities.
Expand Down Expand Up @@ -50,8 +50,7 @@ const rootReducer = combineReducers({
entities,
pagination,
errorMessage,
routing: routeReducer
routing
})


export default rootReducer
13 changes: 3 additions & 10 deletions examples/real-world/store/configureStore.dev.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
import { createStore, applyMiddleware, compose } from 'redux'
import { syncHistory } from 'react-router-redux'
import { browserHistory } from 'react-router'
import DevTools from '../containers/DevTools'
import thunk from 'redux-thunk'
import api from '../middleware/api'
import createLogger from 'redux-logger'
import api from '../middleware/api'
import rootReducer from '../reducers'

const reduxRouterMiddleware = syncHistory(browserHistory)
import DevTools from '../containers/DevTools'

export default function configureStore(initialState) {
const store = createStore(
rootReducer,
initialState,
compose(
applyMiddleware(thunk, api, reduxRouterMiddleware, createLogger()),
applyMiddleware(thunk, api, createLogger()),
DevTools.instrument()
)
)

// Required for replaying actions from devtools to work
reduxRouterMiddleware.listenForReplays(store)

if (module.hot) {
// Enable Webpack hot module replacement for reducers
module.hot.accept('../reducers', () => {
Expand Down
4 changes: 1 addition & 3 deletions examples/real-world/store/configureStore.prod.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { createStore, applyMiddleware } from 'redux'
import { syncHistory } from 'react-router-redux'
import { browserHistory } from 'react-router'
import thunk from 'redux-thunk'
import api from '../middleware/api'
import rootReducer from '../reducers'
Expand All @@ -9,6 +7,6 @@ export default function configureStore(initialState) {
return createStore(
rootReducer,
initialState,
applyMiddleware(thunk, api, syncHistory(browserHistory))
applyMiddleware(thunk, api)
)
}