Home

Issue: 1696

Dynamic Routes generates routes for non existent endpoints

[issue link]

Hi.

I have such setup.

setup

First I thought everything fine

ok

But then I notice that Nuxt generates routes for any value and doesn’t return Error

error

This endpoint moooooney doesn’t exist of course. And If I go to this route I got an error like it should:

404

How to setup everything, so Nuxt understand, that to show only the data that exist?

This is my articles/_section/index.vue file

asyncData ({ req, params, error }) {
    return axios.get(`${process.env.baseUrl}/api/articles/${params.section}`)
      .then((res) => {
        return { articles: res.data }
      })
      .catch(() => {
        error({ statusCode: 404, message: 'Section not found' })
      })
  }

This is my articles/_section/_slug.vue file

asyncData ({ req, params, error }) {
    return axios.get(`${process.env.baseUrl}/api/articles/${params.section}/${params.slug}`)
      .then((res) => {
        return { article: res.data }
      })
      .catch(() => {
        error({ statusCode: 404, message: 'Pooooost not found' })
      })
  }

I have only 5 sections in my API data.

This question is available on Nuxt.js community (#c1520)