I am new in react.js.
(我是react.js的新手。)
How to do redirect in react.js after login ?(登录后如何在react.js中重定向?)
Is it different from Vue.js routing ?(与Vue.js路由不同吗?)
I installed this package.(我安装了这个软件包。)
I read this question.(我读了这个问题。)
I tried in different ways but no one is working.(我尝试了不同的方法,但是没有人在工作。)
Could you please help me with some basic code or any basic tutorial ?
(您能帮我一些基本代码或任何基本教程吗?)
Here is my code
(这是我的代码)
import React, { Component } from 'react';
import Auth from '../services/Auth'
import { Router, Route, Link, IndexRoute, hashHistory, browserHistory, Redirect } from 'react-router-dom'
class Login extends Component {
constructor(props) {
super(props);
this.state = {email: '',password:''};
this.handleChange = this.handleChange.bind(this);
this.handleClick = this.handleClick.bind(this);
}
handleChange (event){
this.setState({[event.target.name]: event.target.value});
}
handleClick(){
var data = {
client_id: 2,
client_secret: 'ispGH4SmkEeV4i5Tz9NoI0RSzid5mciG5ecw011f',
grant_type: 'password',
username: this.state.email,
password: this.state.password
}
fetch('http://127.0.0.1:8000/oauth/token', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify(data)
})
.then((response) => response.json())
.then((responseData) => {
Auth.setToken(responseData.access_token,responseData.expires_in+ Date.now());
this.props.history.push("/dashboard");
})
}
}
export default Login;
I am getting error like below
(我收到如下错误)
ask by abu abu translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…