几天以来,我一直在尝试在登录到主页后重定向我的用户,在我的 App.js 中创建一个回调函数,并通过 loginregisterpage 类组件将其作为道具发送到登录类组件,但这不起作用,有人可以吗看看它并告诉我我错过了什么?谢谢我的代码看起来像这样
应用程序.js
import React from 'react'
import { BrowserRouter as Router, Switch, Route } from 'react-router-dom'
import { HomePage } from './Pages/HomePage/HomePage'
import { LoginRegisterPage } from './Pages/LoginRegisterPage/LoginRegisterPage'
import 'bootstrap/dist/css/bootstrap.min.css'
export class App extends React.Component {
constructor(props) {
super(props);
this.state = {
authenticated: false,
}
this.handleSuccess = this.handleSuccess.bind(this);
}
handleSuccess = (data) => {
this.props.history.push("/")
}
render() {
return (
<Router>
<Switch>
<Route exact path="/">
<HomePage />
</Route>
<Route exact path="/login-register">
<LoginRegisterPage onLoginSuccess={this.handleSuccess} />
</Switch>
</Router> …Run Code Online (Sandbox Code Playgroud)