在React-Router中未定义this.props.history.push

时间:2019-09-12 14:19:24

标签: reactjs react-router history react-props

我要执行history.push 但它不起作用。 我已经用过Router,History等 谁能帮我解决这个问题

register=(e)=>{
    e.preventDefault()
    this.props.history.push('/dashboard')
    }

import React from 'react';
import './App.css';
import Login from './component/login/login'
import Header from './component/header/header'
import { createBrowserHistory } from 'history';


import { Router, Route, Switch } from 'react-router-dom'

const his=createBrowserHistory()

class App extends React.Component {
render(){
return (
  <Router history={his} >
    <div className="App">
      <Header />
      <Switch>
          <Route path="/register" component={Login} exact/>
      </Switch>
    </div>
  </Router>
);

} }

导出默认应用;

0 个答案:

没有答案