任务请求路径渲染 xxx.com/index/news,xxx.com/index/User 这个效果,我将文件树设置为:
pages/ --| index/ -----| News/ -------| index.vue -----| User/ -------| index.vue --| index.vue
但是我无法成功跳转到除根目录以外的其他页面。
我需要做什么来使网页的路径显示所期望的效果?
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
主页(位于根路径)可以安全地命名为
index.vue,没有其他方法可以将页面绑定到/路径。但问题确实是你不能同时拥有同名的页面和文件夹。它们会重叠。
解决方法可以是使用
nuxt.config.js中的自定义路由将根路径/映射到你的主页:router: { extendRoutes (routes, resolve) { routes.push( { name: 'index_home', path: '/', component: resolve(__dirname, 'pages/home.vue') }, ) } },参见
nuxt.config.js / router文档注意:你也可以从这里删除自动创建的
/home路由,它将在routes数组中。