F
F
fred19872019-02-19 13:02:57
Frontend
fred1987, 2019-02-19 13:02:57

Nuxt.js How to catch an error leading to error layout before switching to it and redirect to a custom page?

When receiving an internal error, nuxt redirects to the error layout. I want to change this behaviour. I want to have a redirect to a custom page instead of showing the error layout. Tell me how this can be achieved?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
karambafe, 2019-02-27
@karambafe

If an asynchronous request is made for data on the page, then this can be resolved in the asyncData hook using the redirect method

async asyncData({ redirect }) {
  try {
     // тут делаем асинхронный запрос за данными
  } catch (error) {
     // в случае ошибки выполняем редирект на роут custom-error-page
     redirect('/custom-error-page')
  }
}

K
Klein Maximus, 2019-09-18
@kleinmaximus

As an option, hang a redirect to the desired page in the asyncData method of the layouts/error.vue component

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question