我想重定向到User Profile頁面,一旦用戶使用有效的登錄username和password但是當我單擊Login按鈕時,它不會轉到User Profile(但它會url按預期更改(http://localhost:3000/instructor/banuka)它還應該顯示InstructorLoginFormComponent它沒有顯示的內容。當我點擊什么都沒有發生但我能看到的仍然是login頁面這是我的 InstructorLoginForm.jsximport React, { Component } from "react";import { BrowserRouter as Router, Route, Switch } from "react-router-dom";import InstructorProfile from "./instructor-profile";import InstructorLoginFormComponent from "./instructor-login-form-component";export default class InstructorLoginForm extends Component { constructor(props) { super(props); this.state = { username: "", password: "" }; this.onChangeUsername = this.onChangeUsername.bind(this); this.onChangePassword = this.onChangePassword.bind(this); this.handleOnClick = this.handleOnClick.bind(this); } onChangeUsername(e) { this.setState({ username: e.target.value }); } onChangePassword(e) { this.setState({ password: e.target.value }); } handleOnClick(e) { e.preventDefault(); const path = `/instructor/${this.state.username}`; this.props.history.push(path); }
如何在 ReactJS 中登錄頁面后重定向/轉到用戶配置文件
慕尼黑5688855
2021-06-29 17:54:21