M
M
Mikhail Kostikov2022-02-08 11:45:51
Nginx
Mikhail Kostikov, 2022-02-08 11:45:51

Why is the nuxt generate 404 page not opening?

I run the generate command then start
The 404.html file appears in the dist folder
. I did not change the /layouts/error.vue template.
In nuxt.config.js , generate had fallback: true and routes, target: 'static'.
I enter any non-existent page for example /sdfs , the browser for some reason tries to open it as if it exists and load js that do not exist:
62022b4a28aca900980669.png
Pages that exist open correctly.
nuxt 2.15.8

/layouts/error.vue

<template>
  <v-app>
    <h1 v-if="error.statusCode === 404">
      {{ pageNotFound }}
    </h1>
    <h1 v-else>
      {{ otherError }}
    </h1>
    <NuxtLink to="/"> Home page </NuxtLink>
  </v-app>
</template>

<script>
export default {
  name: "EmptyLayout",
  layout: "empty",
  props: {
    error: {
      type: Object,
      default: null,
    },
  },
  data() {
    return {
      pageNotFound: "404 Not Found",
      otherError: "An error occurred",
    };
  },
  head() {
    const title =
      this.error.statusCode === 404 ? this.pageNotFound : this.otherError;
    return {
      title,
    };
  },
};
</script>

<style scoped>
h1 {
  font-size: 20px;
}
</style>


nuxt.config.js[generate]

generate: {
    fallback: true,
    async routes() {
      const routes = await getRoutes()
      return routes.map(({ url }) => url)
    }
  }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Karabanov, 2022-02-08
@karabanov

Add to config:

error_page 404 /404.html;
location = /404.html {
    # Путь до директории где размещена кастомная страница 404.html
    root /path/to/directory/with/404/html;
    internal;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question