简体   繁体   English

当用户成功登录时,如何通过路由器立即将用户重定向到新页面(密码,用户名是正确的)

[英]How to instantly redirect the user to a new page via router when the user logs in succesfully(password, username are correct)

Via vue.js I've made a login form with a username and password, and set conditions for them. 通过vue.js我创建了一个包含用户名和密码的登录表单,并为它们设置了条件。 When the user submits the correct username and password I want to redirect them to a new page vie the vue.js Router. 当用户提交正确的用户名和密码时,我想通过vue.js路由器将它们重定向到新页面。 So for example if the user is currently located in "localhost8080/", after a successful login I want to immediately send them to "localhost8080/#/profile" 因此,例如,如果用户当前位于“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.
                }
                }

If You using vue-router, better to use programmatic navigation. 如果你使用vue-router,最好使用程序化导航。

Link: https://router.vuejs.org/guide/essentials/navigation.html 链接: https//router.vuejs.org/guide/essentials/navigation.html

if(loginConfirmed) {
    this.$router.push({ path: 'dashboard' });
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当用户使用passportjs成功登录时如何重定向reactjs中的页面 - How to Redirect pages in reactjs when user succesfully logs in using passportjs 用户输入正确的用户名和密码后,如何使提交按钮重定向到另一个页面? - How do you make a submit button redirect to another page after the user has inputted the correct username and password? 输入错误的用户名和/或密码后,如何将用户从登录控件重定向到错误页面? - How to redirect user to an error page from login control upon entering wrong username and/or password? 用户输入正确密码后,如何使提交按钮重定向到另一个页面? - How do you make a submit button redirect to another page after the user has inputted the correct password? 如果用户是真实的,如何使用 VUEX STORE state 在 vue.js 中将用户重定向到主页? - How to redirect user to home page if user is authentic i.e ID or PASSWORD is correct in vue.js using VUEX STORE state? 如何在不重定向到另一个页面的情况下验证用户的用户名和密码? - How to authenticate a username & password of the user without redirecting to another page? 如何重定向到instagram:// user?username = {username} - How to make redirect to instagram://user?username={username} 用户登录后如何重定向回受保护的页面? - How do I redirect back to protected page after user logs in? 当新用户登录同一浏览器时如何注销用户? - How to logout a user when a new user logs in in the same browser? JS:如何在用户刷新页面时将用户重定向到另一个页面? - JS: How to redirect an user to another page when user refresh the page?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM