[英]How to Redirect pages in reactjs when user succesfully logs in using passportjs
[英]How to instantly redirect the user to a new page via router when the user logs in succesfully(password, username are correct)
通过vue.js我创建了一个包含用户名和密码的登录表单,并为它们设置了条件。 当用户提交正确的用户名和密码时,我想通过vue.js路由器将它们重定向到新页面。 因此,例如,如果用户当前位于“localhost8080 /”,成功登录后我想立即将它们发送到“localhost8080 /#/ profile”
validate() {
var email = document.getElementById("email").value;
var atSign = email.indexOf("@");
var error = document.getElementById("error");
var mistakes = "";
var hasErrors = false;
if (this.newP != this.password){
mistakes += "Entered password is incorrect. ";
hasErrors = true;
}
if (atSign === -1) {
mistakes += "The email is missing an '@' sign.";
hasErrors = true;
}
// console.log(this.newP.length)
if (hasErrors === true) {
error.innerHTML = mistakes;
return false;
} else {
alert("Login confirmed");
return true;
//I realize it's supposed to be here, but I do not know
//how to write it.
}
}
如果你使用vue-router,最好使用程序化导航。
链接: https : //router.vuejs.org/guide/essentials/navigation.html
if(loginConfirmed) {
this.$router.push({ path: 'dashboard' });
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.