【发布时间】:2022-01-03 13:25:56
【问题描述】:
使用 Nuxt 3,我阅读了很差的官方文档:https://v3.nuxtjs.org/docs/directory-structure/pages/#dynamic-routes
但我不明白如何使它对动态路由正常工作。
我有我的产品组件:
pages
|___product
|___[slug].vue
我想轻松链接到 [slug] 组件,查看 Vue Router 文档,我这样做了:
<NuxtLink :to="{path: `/product/${product.seo.slug}`, component: Product}" class="product-listing">
.....
</NuxtLink>
它可以工作,但它会重新加载整个页面。
我错过了什么吗?
【问题讨论】:
-
component: Product是什么,在vue router的API中看不到。?如果硬编码 URL 会发生什么?另外,通过你的开发工具检查链接,奇怪的是它不起作用。 -
在文档中看到它:next.router.vuejs.org/guide/essentials/dynamic-matching.html,但即使使用硬编码的 URL,我也不会进行转换,控制台是干净的 :(
-
您在此处链接的是如何手动定义路由器,而不是您传递给
nuxt-link的内容。你有minimal reproducible example吗? -
去 JS 弄这个,Nuxt3 说要依赖这个插件(Vue Router)
-
首选codesandbox或stackblitz,JSfiddle不是最好的。