当使用链接时,路由器按预期工作,但我收到警告[history]不推荐使用pushState;用而不是推。
使用来自react-router-redux的routeActions不起作用,url是更改(http://localhost:3002/addCity),但是如果我按url转到页面,则视图仍然相同(Home)或显示错误:本地主机: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)
答案 0 :(得分:0)
insted createHistory需要使用&#39;历史&#39;
中的createHashHistory为我工作
答案 1 :(得分:0)
请尝试将“react-router-redux”版本更改为“^ 5.0.0-alpha.8”。它解决了我的问题