vue study notes navigation guard

First, what is the navigation guard

   Do something after navigation guard is that you listen from one route to another route to jump, with navigation guard, or you can jump before jumping

Second, the global navigation guard

/ Front guard (Guard) 
router.beforeEach (// listening guard 
    (to, from, Next) => { 
        // jump from the form to 
        document.title = to.meta.title //document.title = to. matched [0] .meta.title nested routing there are two ways, the first nested take a direct route, the second route to get nested parent routing 
        next () // next call is necessary here 

    }) 
// rear hook (hook) rear hook no active call the next function (because the jump has been finished, the subsequent operation is not required) 

router.afterEach ((to, form) => { 
    the console.log ( 'dasdsdasda ') 
}) 
// on next, next () to the next pipeline in the hook, if the entire hook is finished, the navigation state is confirmed (acknowledgment) 
next (' ./')// or next ({path: '/'}) // jump to a different address, current navigation is interrupted, be a new navigation 
// make sure to use the next method, otherwise the hook will not be resolved 
// there routing exclusive guard 
// written in the routing configuration, the only access to this path, in order to trigger the hook function 


// guard in the assembly 
// write in assembly, access path, is about to render When parts of the trigger

Third, the global routing exclusive guard and guard similar, but it only works in one route

Fourth, in the guard assembly (subsequent updates, etc.)

V. Similarly, the guard has a similar function as well as our life cycle functions

  created mounted updated

Guess you like

Origin www.cnblogs.com/LazyPet/p/12175599.html