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
I am using centos 7 64bit system here. I have tri...
I have been learning about algorithms recently an...
VMware vSphere is the industry's leading and ...
Xrdp is an open source implementation of Microsof...
After adding –subnet to Docker network Create, us...
MySQL database storage location: 1. If MySQL uses...
Preface I recently wrote a small demo. Because I ...
Many tables in MySQL contain columns that can be ...
This tutorial is only applicable to Windows syste...
MySQL replication detailed explanation and simple...
Resource merging and compression for two purposes...
This situation usually occurs because the Chinese...
Preface According to the project needs, Vue-touch...
Classification of color properties Any color can ...
Every time I design a web page or a form, I am tr...