Properties of vue-router

Always forget, record it for later use.

$router refers to the router instance, and $route is the currently activated routing information object. It is a read-only attribute and cannot be changed, but it can be watched (monitored).

Attributes:

$router.app : Vue root instance configured with router

$router.mode : routing mode, here is hash

$router.currentRoute : The routing information object of the current route, which contains the information of the current matching route.

method:

router.addRoutes(routes) : Dynamically add routing rules, the parameter is an array that meets the requirements of the routes option.

router.beforeEach(to,from,next) : global front guard

router.beforeEach((to,from,next)=>{
     //... 
})

  When the route changes, the global front guard is executed and accepts three parameters, to, from, and next, which respectively represent the target route that is about to enter, the route that is currently leaving, and the callback function next(). The execution effect of next depends on the parameters. next(), executes the next hook. If the hook is executed, the navigation status is confirm; next(false) interrupts the current navigation and returns to the address corresponding to the from route; next({path:'/'}), jumps to from Define routing address. next(error), if an error instance is passed in, the navigation is terminated and the error is passed to the callback registered by router.onError().

router.beforeResolve() : global parsing guard, called before the navigation is confirmed and after the guard in the lock component and the asynchronous routing component are parsed. The parameters are the same as the global front guard;

router.afterEach() : global post guard

router.afterEach((to,from)=>{
    //....没有next()函数参数,也不会改变导航本身
})

router.go(n) : Accepts an integer as a parameter, similar to window.history.go(n), moves forward or backward a few steps in the browser history

router.push(location) : Jump navigation method, this method will add a new record to the history stack

router.replace(location) : Similar to router.push(), but it will replace the current history record and will not add new records.

router.back() : equivalent to router.go(-1)

router.forward() : equivalent to router.go(1)

router.resolve(location) : parses the target route, accepts an address parameter, returns location, route, href and other attribute information, and can also accept the current default route current and the additional path append on the current route.

router.onReady(callback,[errorCallback]){} : Queue a callback and call it when the route completes the initial navigation.

router.onError(callback) : Register a callback, which will be called when an error occurs during route navigation, but there are requirements for the error situation when it is called:

  1. The error is thrown synchronously in a route guard function

  2. Errors are captured and handled asynchronously in a routing guard function by calling next(error)

  3. During the process of rendering a route, an error occurred when trying to parse an asynchronous component.

route is a routing information object, which contains various information about the current route. The routing object is immutable, and a new object will be generated every time the routing navigation is successful. The return value of router.match(location) is also a routing information object, and the parameters to and from of the navigation guard are also routing information objects.

Attributes:

$route.fullPath : URL after completion of parsing, including the full path of query parameters and hash

$route.path : path, string type, parsed to absolute path

$route.hash : The hash value of the current route (with # sign), if there is no hash value, it is an empty string

$route.name : The name of the current route, if any (used to name routes)

$route.params : a key-value pair object, routing parameters

$route.query : a key-value pair object representing url query parameters

$route.matched : A route record containing all nested path segments of the current route (a copy of the object in the routes configuration array)

$route.redirectedFrom : The name of the route from which the redirection originated, if there is a redirection.

Guess you like

Origin blog.csdn.net/m0_56683897/article/details/128301144