Vue.js gridsome添加路由器元数据的位置

Vue.js gridsome添加路由器元数据的位置,vue.js,authentication,gridsome,Vue.js,Authentication,Gridsome,我想对特定路由进行密码保护,并希望向每个路由添加元数据,如下所示: { path: '/route-path', name: 'route-name', component: ComponentName, meta: { requiresAuth: true } } 这样我就可以登记了 router.beforeEach((to, from, next) 我可以访问main.js中的router.beforeach,但在何处向每个路由添加auth标志?gridso

我想对特定路由进行密码保护,并希望向每个路由添加元数据,如下所示:

{
  path: '/route-path',
  name: 'route-name',
  component: ComponentName,
  meta: {
    requiresAuth: true
  }
}
这样我就可以登记了

router.beforeEach((to, from, next)

我可以访问main.js中的router.beforeach,但在何处向每个路由添加auth标志?gridsome.config.js似乎不起作用?

我也在找同样的。我想到的唯一一件事就是更换
router.options.routes
属性如下:

// main.js

import { myRoutes } from '@/router'

export default function (Vue, { appOptions, router, head, isClient }) {          
  // Set vue plugins                                                                
  Vue.use(Vuex)                                                                  
                                                   
                                                                                 
  // Set default layout as a global component                                       
  Vue.component('Layout', DefaultLayout)                                            
                                                                                 
  router.options.routes = myRoutes                                                                                                      
                                                                                 
  router.beforeEach((to, from, next) => {                                        
    // implement navigation guards                                                       
    next()                                                                       
  })                                                                             
}                   
其中
myRoutes
是路由对象的列表:

// router/index.js

import Component1 from '@/components/Component1.vue'

export myRoutes = [
  {
    path: '/route-path',
    name: 'route-name',
    component: Component1,
    meta: {
      requiresAuth: true
    }
  },
  // ...
]


如果您找到了更好的解决方案,请告诉我。

尽管目前没有文档记录,但您可以使用API并向其传递一个
路由
属性,例如

src/pages.js

module.exports=[
{
路径:“/”,
路线:{
名称:'索引',
元:{
请求权限:false
}
},
组件:'./src/views/Index.vue'
}
]
gridsome.server.js

const pages=require('./src/pages')
module.exports=函数(api){
api.createPage(({createPage})=>{
用于(常量页,共页){
createPage(第页)
}
})
}

我还将页面组件移动到
src/views
目录中,以避免路由自动生成。

您真的能够让它工作吗?我一直无法。。。生成的路由覆盖此。$route