I am new in react.js. How to do redirect in react.js after login ? Is it different from Vue.js routing ? 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