vue2.xPre-concept:Routing hook categoriesThere are 3 categories and 7 hooks in total. The concept of routing and components (for easy understanding of hook functions)Routing and components are two concepts, which can be roughly considered as:
Global routing hooksrouter.beforeEach(to, from, next){ } Pre-navigation guard Before routing router.afterEach(to, from, next){ } Post navigation guard After the route enters router.beforeResolve(to, from, next){ } Resolution guard When parsing a component, all configurations have been read, and all previous levels have passed. Execute before parsing the component Routing configuration guard hookbeforeEnter() is called before reading the routing configuration information Executed before beforeCreate() const router = new VueRouter({ routes: [ { path: '/foo', component: Foo, beforeEnter: (to, from, next) => { } } ] }) Guard hooks in components
By default, you cannot get the component instance However, the following methods can be used to access beforeRouteEnter(to, from, next){ // The callback function of next() is instantiated and executed when entering the route next(vm => { // vm is equivalent to the current component this }) }
The current component is still using the routing address change and will only be executed if the above two conditions are met
Routing hook execution orderEg: jump from component A to component B If there is an update on route B, the following three hooks will be executed each time: vue3.xVue3.x is only slightly different from vue2.x, so we will only explain the differences here. Comparison chartDifferences and Supplements:
The subcomponents in component B will not trigger the routing hook
The subcomponents in component B trigger the routing hooks: onBeforeRouteUpdate and onBeforeRouteLeave
The subcomponents in component B trigger the routing hooks: onBeforeRouteUpdate and onBeforeRouteLeave The above is the detailed explanation of the differences between routing hooks in Vue2.x and Vue3.x. For more information about the differences between routing hooks in Vue2.x and Vue3.x, please pay attention to other related articles on 123WORDPRESS.COM! You may also be interested in:
|
<<: Linux system (Centos6.5 and above) installation jdk tutorial analysis
>>: Install Tomcat on Linux system and configure Service startup and shutdown
Docker is an open source project that provides an...
This is not actually an official document of IE. I...
①. How to use the alias (CNAME) record: In the do...
Table of contents Create a simple springboot proj...
This article shares the specific code of JavaScri...
"What's wrong?" Unless you are accus...
Table of contents 1. Introduction 2. Customize ta...
1. Apache server installation and configuration y...
The latest download and installation tutorial of ...
The default operating mode of MySQL is autocommit...
Record the installation and use of openssh-server...
Of course, it also includes some personal experien...
First of all, this post is dedicated to Docker no...
Preface When scroll events such as scroll and res...
1. Click the server host and click "Virtual ...