使用链接时,路由器按预期工作,但我收到警告历史记录pushState已弃用;请使用推送。
使用react-router-redux中的routeActions不起作用,url已更改(http://localhost:3002/addCity),但视图仍然相同(主页)或显示错误,如果我通过url转到页面例如: localhost:3002/addCity。
git:https://github.com/kirsanv43/Weather.git
减速机:
export default combineReducers({
cities,
routing: routeReducer
});存储配置:https://github.com/kirsanv43/Weather/blob/master/app/redux/config/store.js
import rootReducer from '../reducers'
export default function configureStore(initialState) {
const history = createHistory();
const middleware = syncHistory(history)
const finalCreateStore = compose(
applyMiddleware(middleware)
)(createStore)
const store = finalCreateStore(rootReducer)
middleware.listenForReplays(store);
if (module.hot) {
// Enable Webpack hot module replacement for reducers
module.hot.accept('../reducers', () => {
const nextRootReducer = require('../reducers').default
store.replaceReducer(nextRootReducer)
})
}
return store
}路由器:
const store = configureStore()
ReactDOM.render(
<Provider store={store}>
<Router history={browserHistory}>
<Route path="/" component={App}>
<IndexRoute component={Home}/>
<Route path="addCity" component={AddCity}/>
</Route>
</Router>
</Provider>
,
document.getElementById('root')
);组件:
class CitiesList extends React.Component {
onAddCity = () => {
this.props.route.push('/addCity')
};
render() {
return <div className="weatherContainer">
<ul>
<li className="listItem addBtn"><a onClick={this.onAddCity}><span>ADD CITY</span></a></li>
</ul>
</div>
}
}
function mapDispatchToProps(dispatch) {
return {
route:bindActionCreators(routeActions, dispatch)
}
}
export default connect(mapStateToProps, mapDispatchToProps)(CitiesList)发布于 2016-02-07 23:24:11
insted createHistory需要使用‘createHashHistory’中的历史记录
这对我很管用
发布于 2018-02-09 16:19:51
请尝试将"react-router-redux“版本更改为"^5.0.0-alpha.8”。它解决了我的问题
https://stackoverflow.com/questions/35254414
复制相似问题