如何推動歷史在反應路由器v4?在當前版本的Reaction路由器(V3)中,我可以接受服務器響應并使用browserHistory.push若要轉到適當的響應頁面,請執行以下操作。但是,這在v4中是不可用的,我也不知道如何正確地處理這個問題。在本例中,使用Redux,組件/應用程序-產品-form.js打電話this.props.addProduct(props)當用戶提交表單時。當服務器返回成功時,用戶將被帶到購物車頁面。// actions/index.jsexport function addProduct(props) {
return dispatch =>
axios.post(`${ROOT_URL}/cart`, props, config)
.then(response => {
dispatch({ type: types.AUTH_USER });
localStorage.setItem('token', response.data.token);
browserHistory.push('/cart'); // no longer in React Router V4
});}如何從ReactiveRoutv 4函數重定向到購物車頁面?
3 回答

撒科打諢
TA貢獻1934條經驗 獲得超2個贊
import React, {Component} from 'react';export default class Link extends Component { constructor(props) { super(props); this.onLogout = this.onLogout.bind(this); } onLogout() { this.props.history.push('/'); } render() { return ( <div> <h1>Your Links</h1> <button onClick={this.onLogout}>Logout</button> </div> ); }}
this.props.history.push('/cart');
添加回答
舉報
0/150
提交
取消