Static GitHub Issues

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

prev: Cannot use external component on Heroku production
next: TypeError when using Bookshelf.js

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?

<!--cmty--><!--cmty_prevent_hook--><div align="right"><sub><em>This question is available on <a href="https://nuxtjs.cmty.io">Nuxt.js</a> community (<a href="https://nuxtjs.cmty.io/nuxt/nuxt.js/issues/c1570">#c1570</a>)</em></sub></div>