未能加载资源:服务器以404(未找到)POST状态响应http://localhost:3000/login404(未找



login 1加载资源失败:服务器响应状态为404(未找到(axios firebase react js在提交表单时。这个错误也在firebase函数日志中请有人帮我。。。登录1加载资源失败:服务器的响应状态为404(未找到(POST http://localhost:3000/login 404 Not Found请检查图片从提交时出现此错误



import React, { Component } from 'react'
import withStyles from '@material-ui/core/styles/withStyles'
import PropTypes from 'prop-types'
import AppIcon from '../images/logo.png'
//axios
import axios from 'axios'
//MUi stuff
import Button from '@material-ui/core/Button'
import TextField from '@material-ui/core/TextField'
import Grid from '@material-ui/core/Grid'
import Typography from '@material-ui/core/Typography'
const styles = {
form: {
textAlign: 'center'
},
imgLogo: {
margin: '20px auto 20px auto'
},
button: {
margin: '10px auto 10px auto'
},
textField: {
margin: '10px auto 10px auto'
}
}
class login extends Component {
constructor() {
super();
this.state = {
email: '',
password: '',
loading: false,
errors: {}
}
}
handleSubmit = (event) => {
event.preventDefault();
this.setState({
loading: true
});

axios.post('/login' , {
email: this.state.email,
password: this.state.password
})
.then(res =>{
console.log(res.data);
this.setState({
loading: false
});
this.props.history.push('/');
})
.catch(err => {
this.setState({
errors: err.response.data,
loading: false
})
})
};
handleChange = (event) => {
this.setState({
[event.target.name]: event.target.value
});
}

render() {
const {classes} = this.props;
const {errors , loading} = this.state;
return (
<Grid container className={classes.form}>
<Grid item sm></Grid>
<Grid item sm>
<img src={AppIcon} width="80" height="80" alt="logo" className= 
{classes.imgLogo}/>
<Typography variant="h3" className={classes.pageTitle}>
Login
</Typography>
<form noValidate onSubmit={this.handleSubmit}>
<TextField id="email"
name="email"
type="email"
label="Email"
className={classes.textField}
value={this.state.email}
onChange={this.handleChange}
helperText={errors.email}
error={errors.email ? true : false}
fullWidth
/>
<TextField id="password"
name="password"
type="password"
label="Password"
className={classes.textField}
value={this.state.password}
onChange={this.handleChange}
helperText={errors.password}
error={errors.password ? true : false}
fullWidth
/>
<Button className={classes.button} variant="contained" 
color="secondary" 
type="submit">
Login
</Button>
</form>
</Grid>
<Grid item sm></Grid>
</Grid>
)
}
}
login.propTypes = {
classes: PropTypes.object.isRequired
}
export default withStyles(styles)(login);

检查哪个端口承载您的网站。如果是3000,请检查登录文件所在的文件目录。

最新更新