nuxt middleware

 End the use of middleware nuxt

 

 

Introduction 1. middleware : middleware on amiddleware目录中,中间件是一个js文件,可以使用函数定义一个页面的中间件,会在页面初始化之前调用

// columns in the middleware such as creating a directory baseurl.js file to define the middleware functions 

Import from Axios ' Axios' 
Export default  function ({route, Store, redirect}) {
     IF (store.state) { 
        Alert ( 'Sorry you did not token, Login ' )
         return the redirect (' / Search ' ) 
    } 
} 


// after nuxt-config.js configuration, can be used after each page 

Router: { 
    Middleware: ' BaseURL '     // is js file name 
} 



// but if you do not want every page, you can specify the desired page in 

// the specified function middleware 
middleware: 'baseurl',

 

See the more detailed part of the document nuxt.js

Guess you like

Origin www.cnblogs.com/zxuedong/p/12550155.html