我想知道如何在nuxtjs中重命名路由。
特别是,我有一个名为products的文件夹,其中包含_id.vue和index.vue文件。但是,我不希望路由是www.mysite.com/products/productID,而是www.mysite.com/productID。这就是说,我想从路线中删除产品。
你知道我该怎么做吗?
发布于 2020-05-21 06:05:33
Docks suggest that top-level dynamic routes will work fine。查看示例中的_slug
文件夹。
因此,下面的文件夹结构是有效的:
pages
--| _product/
-----| index.vue
在您的index.vue
中,您可以通过$route
object (check this answer for more details)访问product
参数,因此,它可以包含以下内容:
<!-- pages/_product/index.vue -->
<template>
<div class="flex items-center justify-center text-center py-20">
{{ $route.params.product }}
</div>
</template>
<script>
export default {}
</script>
我已经测试过了,它是有效的。如果你有这个设置,你会进入www.mysite.com/shampoo/
,你会看到shampoo
出现在屏幕上,如果你进入www.mysite.com/r2-d2/
,你会看到r2-d2
,依此类推。
https://stackoverflow.com/questions/61923495
复制相似问题