Answer the question
In order to leave comments, you need to log in
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
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')
}
}
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 questionAsk a Question
731 491 924 answers to any question