nuxt:将隐藏数据传递给路由

nuxt: passing hidden data to route

我需要通过Nuxt-link,

传递两个数据

第一个 ID Id 用于获得单身 Post 并且必须是 hidden

另一个是 title 因为 SEO

曾经在 URL
<NuxtLink to="localePath({ path: `/blog/${post.title}` })">
show Post
</NuxtLink>
``

i have abode code and I don't now how to pass `ID`

像这样创建文件:

然后重定向到博客 post:

<NuxtLink
  :to="{
    name: 'blog-title',
    params: { title: 'vue', id: 123 },
  }"
>
  Go to Blog post page and pass user id
</NuxtLink>

并在博客页面文件中获取 id:

this.$route.params.id

它是隐藏的,因为文件名只包含_title.

演示:https://codesandbox.io/s/shy-fast-d2r5k?file=/pages/blog/_title.vue

但是老实说我不太明白你想做什么。您应该从标题中获取 id。现在,如果有人得到 link 到那篇文章: www.[xyz].com/blog/vue, 他们不会获得 id,因为它是隐藏的,并且只有当他们从特定的前一页重定向时才会被传递。如果用户在新(空白)卡中打开此 link,则相同。它将在看不到隐藏 ID 的服务器上呈现。

检查这个:

https://d2r5k.sse.codesandbox.io/主页 > 博客 = 有效https://d2r5k.sse.codesandbox.io/blog/vueblog = 它不起作用 - 没有 id