B
B
bormor2021-02-10 17:44:05
Vue.js
bormor, 2021-02-10 17:44:05

Nuxt Vue Apollo. How to redirect to a 404 page in case of an error?

In asyncData() we can redirect with nuxtContext.error({statusCode:404, message: '...'})

In apollo I try to do something like this,

apollo: {
    pets: {
      prefetch: true,
      query: gql`
        query {
          allPets {
            id
            name
          }
        }
      `,
      update: (data) => data.allPets,

      error(errorData) {
          this.$root.error({ statusCode: 400, message: 'Error 400. Bad request' });
      },
    },
  },


But the redirect happens only in SPA mode.
Those. when we load the page for the first time or reload the page - the request is executed on the Nuxt Server side and the application crashes with an error
6023f11839959775871377.png

How can I make the redirect on error pages work in all cases?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question