Vue-router route judgment page is not logged on to the instance on the logon page, vue-router is not logged on
As follows:
Router. beforeEach (to, from, next) => {if (. matched. some (record => record. meta. requireAuth) {// determine whether the route requires the logon permission if (token) {// determine whether the current token exists next ();} else {next ({path: '/login', query: {redirect:. fullPath} // use the route entry path as the parameter. After Successful Logon, the route entry will be redirected to the route.} else {next ();}});
Before that, add a meta attribute to the route:
{Path: '/Index', meta: {title: '', requireAuth: true, // Add this field to enter this route },}
Note:However, the fact is that most of the login time does not jump, so here you need to add a paragraph in the login jump path:
If (this. $ route. query. redirect) {// let redirect = decodeURIComponent (this. $ route. query. redirect); let redirect = this. $ route. query. redirect; this. $ router. push (redirect);} else {this. $ router. push ('/');}
The above example of the Vue-router route judgment page not logged on to jump to the login page is all the content shared by Alibaba Cloud. I hope you can provide a reference and support for the customer's house.