By determining whether the user has logged in, if not logged in, it will jump to the login login route, and if logged in, it will jump normally.
1. First, give a status before and after the user logs in to identify whether the user is logged in (it is recommended to use vuex);
Just use vuex to express it, and you can't go to the official website to see more;
import Vue from ‘vue‘ import Vuex from ‘vuex‘ (Vuex); var state = { isLogin:0, //At the beginning, give isLogin=0 to indicate that the user is not logged in}; const mutations = { changeLogin(state,data){ = data; } };
2. Change the login status when the user logs in;
this.$(‘changeLogin‘,‘100‘) //Change the login status after logging in isLogin = 100;
3. The key point is here;
Add a navigation hook to your routing portal, and what it means depends on the code;
1. Set up the route to verify
{ path: ‘/admin‘, component: Admin, meta:{auth:true} // Setting up the current route requires verification. You don’t need to write routes that do not require verification; don’t ask why, go to the official website yourself }
2. Routing and verification
((to,from,next) => { if(( m => )){ // Verify the routeif(==‘100‘) { // Log innext() // Jump to the page you set normally} else{ // If you are not logged in, you will jump to the login interface. query:{ Rurl: } means passing the current routing information over and conveniently jump back after logging in; next({path:‘/login‘,query:{ Rurl: } }) } }else{ next() } })
The above article on the function of determining whether the user is logged in during vue routing jump is all the content I have shared with you. I hope you can give you a reference and I hope you can support me more.