LoginSignup
0

posted at

updated at

Nuxt.js 3 の動的ルーティングでハマったこと

例えば /posts/1, /posts/2 のようにアクセスしたい場合
Nuxt.js 2では以下の書き方でした

pages/
--| about.vue
--| posts/
----| _id.vue

Nuxt.js 3では以下のように []で囲む必要があります

pages/
--| about.vue
--| posts/
----| [id].vue

[id].vue内でid値にアクセスする場合は以下で可能です(Vue.js 3のsetup使用時)

<script setup lang='ts'>

const route = useRoute()
const id = route.params.id

</script>

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
What you can do with signing up
0