Home > OS >  Nuxt 3 Routing : "Simple" dynamic route return 404 error
Nuxt 3 Routing : "Simple" dynamic route return 404 error

Time:05-22

I'm trying to make a simple dynamic link with nuxt3 ("3.0.0-rc.3") and I cannot reach dynamic slug url. I followed this page but it doesn't seem to work for me : https://nuxtjs.org/examples/routing/dynamic-pages

Here is my simple page structure :

pages/
   index.vue
   category/
       _id.vue

When I try to reach my localhost:3000/category/test I have the 404 error page with the message "Page not found: /category/test".

Here is the link in my "index.vue" file :

<NuxtLink to="/category/test">Test</NuxtLink>

Here is the content of my "_id.vue" file :

<template>
  <div>
    <h1>Project: {{ $route }}</h1>
  </div>
</template>

<script>
export default {}
</script>

<style>
</style>

CodePudding user response:

In Nuxt 3 the dynamic routes are written like [id] instead of _id :

pages/
   index.vue
   category/
       [id].vue

for more details check this https://v3.nuxtjs.org/guide/directory-structure/pages#dynamic-routes

  • Related