【发布时间】:2018-10-03 12:06:15
【问题描述】:
我是 react.js 的新手。登录后如何在 react.js 中进行重定向?它与 Vue.js 路由有什么不同?我安装了this 包。我读了this 的问题。我尝试了不同的方式,但没有人在工作。
您能帮我一些基本代码或任何基本教程吗?
这是我的代码
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;
我收到如下错误
【问题讨论】:
-
您能否分享一些您已经尝试过的代码,以便我们帮助您修复它?
-
我分享了一些代码@3Dos。谢谢。
标签: javascript reactjs react-router