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
When learning mybatis, I encountered an error, th...
This article introduces a tutorial about how to u...
1. Introduction MySQL is used in the project. I i...
Method 1: hostnamectl modification Step 1 Check t...
This article shares the specific code of Javascri...
This article shares the installation and configur...
This is the installation tutorial of mysql5.7.18....
Table of contents Principle Source code analysis ...
Idea: Just sort randomly first and then group. 1....
This article shares the specific code of JavaScri...
Table of contents 1. Install Docker 2. Create a c...
Table of contents How to set cookies Disadvantage...
By default, /etc/default/docker configuration wil...
Table of contents 1. typeof 2. instanceof 3. Cons...
1. CSS file naming conventions Suggestion: Use le...