vuejs / vue-router

🚦 The official router for Vue 2
http://v3.router.vuejs.org/
MIT License
18.99k stars 5.06k forks source link

Doc: missing RouteRecord type definiton #2634

Open Fiouz opened 5 years ago

Fiouz commented 5 years ago

Version

3.0.2

Reproduction link

https://router.vuejs.org/api/

Steps to reproduce

  1. Read the API documentation at https://router.vuejs.org/api/#routes for the routes router construction options and see that the routes field is designated as an array of RouteConfig (with an accompanying definition of that type).
  2. Read the API documentation at https://router.vuejs.org/api/#route-object-properties for $route.matched and see that the copy of the aforementioned routes option is now designated as an array of RouteRecord (with not definition of that type)

What is expected?

If the latter is a copy of the former, it should be expected that it should be the same object type or that an explicit relationship between the 2 types be mentioned in the API doc as a canonical definition.

What is actually happening?

There is no canonical definition of what a RouteRecord type is, we only have an example that denotes the array of RouteConfig and we don't understand why copying a type does not result of an instance of the same type.

posva commented 5 years ago

it's a different presentation but still the same information. Not sure what I will do here but I will see

silk9333 commented 4 years ago

RouteConfigThe type is the basic information that defines the route, and the configuration tells the program the view that needs to be obtained and the parameters passed, etc.. In the process of instantiating VueRouter, these configuration items are obtained through the createMatcher=>createRouteMap=>addRouteRecord function to generate a tree of the RouteRecord structure. It adds the upper and lower node information of each route configuration and the attributes hanging on the generated router-view instance. The specific code is as follows:

  var record              = {
    path: normalizePath(path, parent),
    components: route.components || { default: route.component },
    instances: {},
    name: name,
    parent: parent,
    matchAs: matchAs,
    redirect: route.redirect,
    beforeEnter: route.beforeEnter,
    meta: route.meta || {}
  }

So saying'Route records are the copies of the objects in the routes configuration Array (and in children Arrays)' is unreliable. RouteConfig is a static property type for configuring vueRouter RouteRecord is the tree node type when vueRouter is running