鍍金池/ 問答/HTML5  HTML/ react里用browserHistory.push來實現(xiàn)點擊跳轉(zhuǎn)路由報錯 'p

react里用browserHistory.push來實現(xiàn)點擊跳轉(zhuǎn)路由報錯 'push' of undefined

react里用browserHistory.push來實現(xiàn)點擊跳轉(zhuǎn)路由報錯 Cannot read property 'push' of undefined

import React, { PureComponent } from 'react';
import { connect } from 'dva';
import { browserHistory } from 'react-router'
import { Table, Alert, Divider, Menu, Dropdown, Icon } from 'antd';

stockDetail(record) {
    let id = record.id;
    const path = `/stock/monit-device/${id}`
    browserHistory.push(path)
};

render() {
    const columns = [
      {
        title: '操作',
        align: 'center',
        key: '11',
        render: (text, record, index) => (
          <div>
            <a onClick={() => this.stockDetail(record)}>詳情</a>
          </div>
        ),
      },
    ];
  }
回答
編輯回答
葬憶

react-router@4中移除了,需要額外引入history庫。

import createHistory from 'history/createBrowserHistory';
2017年4月3日 22:54
編輯回答
礙你眼

你好,我引用了,怎么還是undefined

const { tabActiveKey } = this.props;

let prevStep = tabActiveKey.substring(tabActiveKey.lastIndexOf("/"));
prevStep = tabActiveKey.replace(prevStep,'')
console.log(prevStep)
browserHistory.push(prevStep)

2017年4月5日 17:59