Uncaught TypeError:无法读取未定义的属性“ push”(React-Router-Dom)

Uncaught TypeError:无法读取未定义的属性“ push”(React-Router-Dom),第1张

Uncaught TypeError:无法读取未定义的属性“ push”(React-Router-Dom)

为了

history
App
组件中使用,请与配合使用
withRouter
withRouter
仅当您的组件未收到时,才需要使用
Routerprops

如果您的组件是 由路由器渲染的 组件的 嵌套子代, 或者 您尚未将路由器道具传递给它, 或者 该组件根本未链接到路由器
,并且作为独立于 该组件 的组件呈现,则 可能会发生这种情况路线。

import React from 'react';import { Route , withRouter} from 'react-router-dom';import Dashboard from './Dashboard';import Bldgs from './Bldgs';var selectedTab;class App extends React.Component {  constructor(props) {    super(props);    this.handleClick = this.handleClick.bind(this);    selectedTab = 0;  }  handleClick(value) {    selectedTab = value;    // console.log(selectedTab);    this.props.history.push('/Bldgs');    // console.log(this.props);  }  render() {    var _this = this;    return (      <div>        <Route exact path="/" render={(props) => <Dashboard {...props} handleClick={_this.handleClick} />} />        <Route path="/Bldgs" component={Bldgs} curTab={selectedTab} />      </div>    );  }}export default withRouter(App);

文档
上withRouter



欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5614926.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-15
下一篇2022-12-15

发表评论

登录后才能评论

评论列表(0条)

    保存