通过目录提供
读取目录结构,编译时态
//在运行时态就会消失
import.meta.glob('路径')
const pages = import.meta.glob('../views/**/page.js',{
eager:true,
import:'default'
})
const comps= import.meta.glob('../views/**/page.js')
//Object.entries() 静态方法返回一个数组,包含给定对象自有的可枚举字符串键属性的键值对。
cosnt routes = Object.entries(pages).map(([path,meta])=>{
console.log(path,page)
cosnt comPath = path.replace('page.js','index.js')
path = path.replace('../views,'').replace('/pages.js)
const name = path.split('/').filter(Boolean).join('-') || 'index'
return {
path,
name,
component:comps[comPath],
meta:meta
}
})