W
W
WebDev2019-02-08 12:36:35
JavaScript
WebDev, 2019-02-08 12:36:35

How to disable error page in nuxt?

In nuxtjs, layouts has an error.vue file. When opening a non-existent page, this file opens and the user sees a beautiful error page.
The problem is that this page opens even when there is just an error in the code. For example, when a button is clicked, the script is executed
this.title = user.info.name;
AND the error "get property name of undefined" appears in the console, because the user object does not have an info property.
So, because of this error, a screen with an error.vue error immediately opens.
How to disable this behavior?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
mrFlyer, 2019-02-08
@mrFlyer

I think you need not to disable the behavior, but to exclude such a situation.
I suspect that the error occurs between the start of the application and the download of data from the server?
Set a temporary title like this.title = "Loading data", and when the data is loaded, write the correct title.

P
profesor08, 2019-05-01
@profesor08

Here is what this file should look like: https://nuxtjs.org/guide/views/#error-page
This page pops up if the required page is not found. So what happens when the button is pressed? Maybe there is a change of route to some / undefined? And that means the error page is loaded.

A
anton-smolko, 2019-07-28
@anton-smolko

Try wrapping the request in a try-catch construct

try {
this.title = user.info.name;
} catch(e) {
return;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question