Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/399.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript React路由器dom';他什么也不做_Javascript_Reactjs - Fatal编程技术网

Javascript React路由器dom';他什么也不做

Javascript React路由器dom';他什么也不做,javascript,reactjs,Javascript,Reactjs,我正在开发一个身份验证系统(我目前正在测试这个系统,但没有发送数据),但它没有做任何事情。我在这里做错什么了吗 import React, { Component } from 'react'; import { withRouter, Link, Redirect, useHistory } from 'react-router-dom'; class Login extends Component { constructor(props) { super(prop

我正在开发一个身份验证系统(我目前正在测试这个系统,但没有发送数据),但它没有做任何事情。我在这里做错什么了吗

import React, { Component } from 'react';
import { withRouter, Link, Redirect, useHistory } from 'react-router-dom';


class Login extends Component {
    constructor(props) {
        super(props);
        this.state = {
            email: '',
            password: '',
        };
    } 
    login(event) {
        event.preventDefault();
        return <Redirect to="/home"></Redirect>
    }
    render() {
        return (
            <div className="login">
                <img src="images/tradecast-logo.png"/>
                <h2>Employee Management System</h2>
                <form onSubmit={this.login}>
                    <h1>Inloggen</h1>
                    <p>E-mail</p>
                    <input type="text" name="email" placeholder="E-mail" />
                    <p>Wachtwoord</p>
                    <input type="password" name="password" placeholder="Wachtwoord"/>
                    <Link to="/forgot-password">Wachtwoord vergeten</Link>
                    <div className="btns">
                        <button type="submit">Aanmelden</button>
                        <Link className="btn-register" to="/register">Registreren</Link>
                    </div>
                </form>
                <p className="copyright">&copy; {new Date().getFullYear()} TradeCast Employee Management by Jens Bouma</p>
            </div>
        )
    }
}
        
export default withRouter(Login);
        
import React,{Component}来自'React';
从“react router dom”导入{withRouter,Link,Redirect,useHistory};
类登录扩展组件{
建造师(道具){
超级(道具);
此.state={
电子邮件:“”,
密码:“”,
};
} 
登录(事件){
event.preventDefault();
返回
}
render(){
返回(
员工管理系统
因洛根
电子邮件

瓦赫特伍德

瓦赫特伍德酒店 安梅尔登 登记员

©;{new Date().getFullYear()}Jens Bouma的TradeCast员工管理

) } } 使用路由器导出默认值(登录);
正如前面所说,重定向必须被呈现,而不仅仅是返回。作为替代,因为您使用的是类组件,所以可以使用
this.props.history.push(“/home”)

正如前面所说,重定向必须呈现而不是返回。作为替代,因为您使用的是类组件,所以可以使用
this.props.history.push(“/home”)

重定向将在呈现函数this.context.history.push(“/home”)中工作


重定向将在呈现函数this.context.history.push(“/home”)中工作


这回答了你的问题吗?这回答了你的问题吗?好的,夫人,黛安好的,夫人,黛安
     this.context.history.push("/home")