Nuxt 2 SSG 404 page returns 200 from server

105 views Asked by At

I generated my website with Nuxt 2 SSG.

I created my error page in layout/error.vue as specified in documentation

<template>
  <div>
    <h1>Error page</h1>
  </div>
</template>

<script>
  export default {
    props: ['error'],
    layout: 'error'
  }
</script>

In my nuxt.config.js

  generate: {
    crawler: false,
    fallback: '404.html',
    routes: //routes
  },

  router: {
    extendRoutes(routes, resolve) {
      routes.push({
        name: 'custom',
        path: '*',
        component: resolve(__dirname, 'layouts/error.vue')
      })
    }
  },

The problem: my SSG page shows 404 page correctly, but response from server is 200, not 404.

If I run npm run dev on my local and remove extendRoutes, it works fine. But once I generate files with nuxt generate and run nuxt start, the 404 page return 200.

I wonder it's possible to control response from server with SSG.

0

There are 0 answers