Does vue-router addRouter add a route to add a route forward?

  1. I added some routes, followed by 404 routes

{

path: "/*",
name: "error-404",
meta: {
    title: "404-"
},
component: () => import("@/views/error-page/404.vue")

}
and then add a route, the latter route does not match at the time of access, is the latter route added to the front?

Mar.24,2021

just * as if you don't need /


ide/essentials/dynamic-matching.html-sharp%E5%8C%B9%E9%85%8D%E4%BC%98%E5%85%88%E7%BA%A7" rel=" nofollow noreferrer "> match priority : sometimes, multiple routes can be matched on the same path, and the matching priority is in the order in which the route is defined: whoever defines it first has the highest priority.
that is, when a new route is added, it is added to the back.

the code does special handling for * routes.
most people's understanding of * is a backup route, that is, when no other route matches, use the route corresponding to * .
Source src the 29-35 line of the create-route-map.js file below is the line that specifically puts the * route to the last side:

// ensure wildcard routes are always at the end
for (let i = 0, l = pathList.length; i < l; iPP) {
  if (pathList[i] === '*') {
    pathList.push(pathList.splice(i, 1)[0])
    l--
    i--
  }
}

to sum up, when adding routes, add routes in the order defined by the route, and finally change the * route to the last .

Menu