Home

Issue: 1748

How do I throw a 404 in a dynamic route when when id does not exist?

[issue link]

I have a page with a dynamic route something like this:

async fetch({ store, route, app }) {
    let url = `/api/${route.params.id}`
    let data = await app.$axios.$get(url)
    if (data.items.length === 0) {
      // there's no data this should be a 404
    }
    store.commit('item', data.Items[0])
  }

How can I throw that 404 in the if statement?

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