亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何推動歷史在反應路由器v4?

如何推動歷史在反應路由器v4?

炎炎設計 2019-07-01 16:05:40
如何推動歷史在反應路由器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');要重定向到Cart頁面,它將保存在歷史對象中。


查看完整回答
反對 回復 2019-07-01
  • onemoo
    onemoo
    這個題很有意思。 你不覺得,提問人的題目和前面的回答都是“機翻”的嗎? 我最近發現問答區有很多類似的現象,這是有人在惡意刷分嗎?!
  • 3 回答
  • 0 關注
  • 570 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號