gpt4 book ai didi

react-router - 路由不适用于react-router-redux操作

转载 作者:行者123 更新时间:2023-12-02 04:26:49 27 4
gpt4 key购买 nike

当使用链接时,路由器按预期工作,尽管我收到警告 [history] ​​pushState is deprecated;使用推送代替。

使用react-router-redux中的routeActions不起作用,url已更改( http://localhost:3002/addCity ),但 View 仍然相同(主页)或显示错误,如果我按url转到页面,例如: localhost:3002/添加城市。

git:https://github.com/kirsanv43/Weather.git

reducer :

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)

最佳答案

安装的createHistory需要使用'history'中的createHashHistory

对我有用

关于react-router - 路由不适用于react-router-redux操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35254414/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com