Nuxt 自定义路由
步骤:
- 在根目录中创建一个 router (目录名字自定义),其下创建一个 index.js(其名字自定义)。如下:
![]()
- 在 router -> index.js 中添加如下代码:
// 引入path import path from 'path' // 要使用获取当前路径 process.cwd() const resolve = (pagePath: string) => path.resolve(process.cwd(), `./${pagePath}`) const routers = [ { path: '/', name: 'index', component: resolve('pages/index.vue'), meta: { title: '首页', icon: 'icon-home' } } ] const router = { base: '/', extendRoutes: (routes: any) => { routes.length = 0 routes.push(...routers) } } export default router
extendRoutes 说明可以查看 https://www.nuxtjs.cn/api/configuration-router
- 在 nuxt.config.js 中引入 路由。
运行 yarn dev 或者 npm run dev


浙公网安备 33010602011771号