How to make a working layout for a nuxt.js 404 page

Viewed 22

I made a layout with for the 404 page, this works if I don't have a Slug in my project If there is a slug in my project, then it does not work, how to redirect to the 404 layout if the response from the API comes false

Im use Nuxt 2

1 Answers

Answer: You can redirect the user to 404 page by throwing the an error like so
if (condition didn't met) throw ({statusCode: 404})

Unrelated but helpful: You can also use advanced middleware to redirect the user to this page if you wanted the user to not enter that specific URL. This is because of the security options. You can achieve it by using a middleware and setting the status code to 404.

Related