英文:
I need to use /index as part of url on nuxt2
问题
我无法提供代码部分的翻译,请提供您需要的文本翻译。
英文:
Task request path rendering xxx.com/index/news, xxx.com/index/User this effect,I set the file tree to:
pages/
--| index/
-----| News/
-------| index.vue
-----| User/
-------| index.vue
--| index.vue
But I can't successfully jump to other pages except the root directory.
What do I need to make the path of the webpage show the desired effect?
答案1
得分: 1
主页(位于根路径)可以安全地命名为 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
数组中。
英文:
The home page (at the root path) can safely be named index.vue
, there is no other way to bind a page to the /
path.
But indeed, the problem is that you can't have both a page and a folder named the same. They will overlap.
A solution for this can be to use a custom routing from the nuxt.config.js
to map the root path /
to your home page:
router: {
extendRoutes (routes, resolve) {
routes.push(
{
name: 'index_home',
path: '/',
component: resolve(__dirname, 'pages/home.vue')
},
)
}
},
See nuxt.config.js / router
documentation
Note: you could also remove the automatically created /home
route from here, it will be in the routes
array.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论