Nuxt router 自定义

1、根目录下新建re-router.js

/**
 * @description 自定义页面路由
 * 
 * 字段说明:
 * path:页面路径
 * name:名称(大驼峰命名)
 * component:文件路径
 **/ 

import path from 'path'

const resolve = (pagePath) => path.resolve(process.cwd(), `./${pagePath}`)

export const $routes = [{
        path: '/index',
        name: 'Index',
        component: resolve('pages/index.vue'),
    }]
const extendRoutes = (routes) => {
    routes.push(...$routes)
}

export default { base: '/', extendRoutes } // base定义基础路由

2、配置

>>>nuxt.config.js

import reRouter from './re-router'

router: reRouter,

3、访问

 

posted @ 2022-08-23 17:33  忙着可爱呀~  阅读(27)  评论(0)    收藏  举报