1.修改路由文件
import {createRouter,createWebHashHistory} from 'vue-router'
let routes = [];
let url;
const files = require.context("/src", true, /\.vue$/);
files.keys().forEach(key => {
if(files(key).default["controller"] != undefined){
url = files(key).default.controller()["url"]
console.log(`页面:${key}\t\t路由:${url}`)
routes.push({
path: url,
component: () => import("/src/"+key.split('./').join('')),
name: key.split('./').join('').split('.vue').join(''),
})
}
})
const router = createRouter({
history: createWebHashHistory(),
mode: 'history',
routes: routes
})
export default router
2.在vue页面的export default里,设置当前页的路由
export default {
controller() {return {"url": "/test"}},
data() {
return {}
}
}
3.访问localhost:8080/test
|