PrefaceAddRoutes official introduction: Function signature:
Add more routing rules dynamically. The argument must be an array conforming to the routes option. When I was working on the vue backend permission management system these two days, I found that after adding routes using addRoute provided by vue, two bugs would appear. Let's see how to solve them~ 1. 404 Page 1. CausesAfter adding dynamic routing using addRoutes provided by vue, the routing setting for the 404 page is no longer at the end of the routing 2. SolutionAdd the route for the 404 page to the end of the dynamic route The code is as follows (example): // xxx => dynamic route array that the user has xxx.push({ path: '*', redirect: '/404', hidden: true }) // Dynamically add routing configuration router.addRoutes(xxx) 2. Refresh the white screen 1. CauseDynamic routing is not fully loaded when refreshing 2. SolutionAfter the route is added, enter the page The code is as follows (example): if (user's dynamic routing is not loaded) { //Solve the white screen bug that occurs when refreshing next({ ...to, // The purpose of next({ ...to }) is to ensure that the route is added before entering the page (which can be understood as re-entering) replace: true // Reenter once, do not keep duplicate history}) } else { next() } 3. Routing Duplicates 1. CauseThe route settings are added through router.addRoutes(xxx). When you log out, they are not cleared. When you log in again, they are added again, so there are duplicates. 2. SolutionThe code is as follows (example): // Reset the route export function resetRouter() { const newRouter = createRouter() router.matcher = newRouter.matcher // Reset the matching path of the route} This method re-instantiates the route, which is equivalent to changing a new route. The previously added route no longer exists. You only need to call it when logging out. SummarizeThis is the end of this article about solving problems when using addRoutes in Vue projects. For more information about Vue using addRoutes, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Solution to the problem of session failure caused by nginx reverse proxy
>>: Solve the installation problem of mysql8.0.19 winx64 version
webkit scrollbar style reset 1. The scrollbar con...
You may have set a MySQL password just now, but f...
Common nmcli commands based on RHEL8/CentOS8 # Vi...
1. Data backup 1. Use mysqldump command to back u...
This is my first time writing a blog. I have been...
Grayscale release refers to a release method that...
1. Introduction Elasticsearch is very popular now...
What is HTML? HTML is a language used to describe...
1. Remove MySQL a. sudo apt-get autoremove --purg...
Table of contents Effect Start creating text Firs...
MySQL is a relational database management system....
To debug js code, you need to write debugger in t...
This article records the installation and configu...
Install zip decompression function under Linux Th...
Table of contents Importing JavaScript 1. Interna...