如何设置`vite-plugin-pages',找不到模块`〜pages'
我正在尝试在的帮助下,使用VITE设置基于文件系统的路由。 vite-plugin-pages
。
我使用YARN创建了项目,用
,并通过vue-ts
作为选项创建viteyarn添加vite-plugin-pages -dev ,<代码>纱线添加vue-router
。
在GitHub上的README之后,我已将以下内容添加到我的vite.config.ts
:
import Pages from 'vite-plugin-pages'
export default {
plugins: [
// ...
Pages(),
],
}
但是,在下一步中,in main.ts
:
import { createRouter } from 'vue-router'
import routes from '~pages'
const router = createRouter({
// ...
routes,
})
我似乎无法从〜页
导入。我找不到模块。 vue-router
本身正常工作,因为我可以创建一个路由器罚款,我可以自己声明路由
自己。在A 从“虚拟:生成页面” 导入路由,我不知道这两个工作方式。
因此,问题是,我将如何生成动态路线,从整体上设置vite-plugin-pages
?
I'm trying to set up file system based routing for a Vue 3 application using Vite with the help of vite-plugin-pages
.
I created the project using yarn create vite
with vue-ts
as the options and added the plugin via yarn add vite-plugin-pages --dev
, yarn add vue-router
.
Following the readme on the github, I have added the following to my vite.config.ts
:
import Pages from 'vite-plugin-pages'
export default {
plugins: [
// ...
Pages(),
],
}
However, at the next step, in main.ts
:
import { createRouter } from 'vue-router'
import routes from '~pages'
const router = createRouter({
// ...
routes,
})
I cannot seem to import from ~pages
. I cannot find the module. vue-router
itself is working fine, as I can create a router fine, declaring the routes
myself. In a vite template, they seem to be using import routes from 'virtual:generated-pages'
instead and I have no idea how either works.
So, the question is, how would I go about generating the dynamic routes and as a whole, set up the usage of vite-plugin-pages
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以尝试这样的尝试:
然后在
main.js
中You can try like this:
Then in
main.js
您还可以在任何类型声明中声明参考。
You can also declare the reference in any of your type declarations.