Vue-router route judgment page is not logged on to the instance on the logon page, vue-router is not logged on

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.