Vue route of Vue routing plug-in


Vue routing plug-in, vuer router, enables the official route management of Vue to be highly coupled with Vue

1. Use of Vue router

import Vue from 'vue'
Import router from 'Vue router' // import route component


new Router({
  Mode: 'history', // two modes of routing hash and history default to history mode
  routes: [
   path: '/',
   name: 'home',
   component: () => import(xxx.vue)
   path: '/about',
   name: 'about',
   component: () => import()

2. Route jump



Get value of route


Route post mode value transfer


3. Route backward



4. Routing progress


5. Replace the current route, which will not appear in the route history


6. The object property of the current route (remember that it is a lowercase $route and there is no r)

This. $route.path current route path

This. $ current route name

This. $ when passing parameters in post mode, get the value of ID

This. $ get gets the value of ID when passing parameters

This. $route.hash the hash value of the current route, with#


The class name of the currently active route. The default is “router link active”


When switching routes, the page scrolls to the specific bit

9. Tag tag in router link to generate specific HTML elements of tag

10. Specific rendering place of router view routing component

11. All routing hook functions (navigation first)

11.1 router.beforeeach

11.2 router.beforeresolve global resolution guard

11.3router.aftereach global rear guard

11.4 before enter route exclusive guard

Guard inside component

11.5 before route enter

11.6 before routeupdate

11.7 before route leave

/*Global front guard*/
router.beforeEach(function (to, from, next) {
 //To route to be routed
 //Route from left
 //Next goes to the next route, otherwise it will not go to the next route
 Console.log ('global front guard ')

/*Global analysis guard*/
router.beforeResolve((to, from, next) => {
 //To route to be routed
 //Route from left
 Console.log ('global resolution guard ')

/*Global rear guard*/
router.afterEach((to, from) => {
 //To route to be routed
 //Route from left
 Console. Log ('global post guard ')
/*Component exclusive guard*/
   beforeEnter(to, from, next) {
    Console.log ('exclusive guard in component ')
beforeRouteEnter(to, from, next) {
  Console. Log ('guard in component enters')
 beforeRouteUpdate(to, from, next) {
  Console. Log ('guard update in component ')
 beforeRouteLeave(to, from, next) {
  Console. Log ('before guard in component leaves')

Order of execution,

1. The guard in the front assembly leaves

2. Global front guard

3. Route exclusive guard

4. Guard access in the assembly

5. Global analysis guard

6. Global rear guard

Or when refreshing components (/ about jumps to / about? Id = 1111)

1. Global front guard

2. Guard update in components

3. Global analysis guard

4. Global rear guard


The above is the example code of Vue route introduced by Xiaobian to you. It’s very good. It has certain reference value. Please refer to it if you need!