Vue-router: onError is undocumented

Created on 8 Jan 2018  路  2Comments  路  Source: vuejs/vue-router

Version

3.0.1

Reproduction link

https://router.vuejs.org/en/installation.html#

Steps to reproduce

Look at the docs
Try to find a mention of onError that describes appropriate usage.
Fail to find it.

What is expected?

Documentation of this method

What is actually happening?

Documentation of this method is not present

Most helpful comment

Why was this closed? I've just been dealing with this exact same issue in vue-router 3.0.1 and can assure you it is not fixed. The documentation covers onError here: https://router.vuejs.org/api/#router-onerror but there is absolutely no mention of any expected usage, and it even suggests that it is purely a no-argument callback that you must provide. I see from examples and discussions on-line that people treat it as a callback that is to take some sort of error parameter when it is called, but the documentation is completely silent on the matter. This is all it says:

router.onError

Signature:

router.onError(callback)

Register a callback which will be called when an error is caught during a route navigation. Note for an error to be called, it must be one of the following scenarios:

The error is thrown synchronously inside a route guard function;

The error is caught and asynchronously handled by calling next(err) inside a route guard function;

An error occurred when trying to resolve an async component that is required to render a route.

All 2 comments

Why was this closed? I've just been dealing with this exact same issue in vue-router 3.0.1 and can assure you it is not fixed. The documentation covers onError here: https://router.vuejs.org/api/#router-onerror but there is absolutely no mention of any expected usage, and it even suggests that it is purely a no-argument callback that you must provide. I see from examples and discussions on-line that people treat it as a callback that is to take some sort of error parameter when it is called, but the documentation is completely silent on the matter. This is all it says:

router.onError

Signature:

router.onError(callback)

Register a callback which will be called when an error is caught during a route navigation. Note for an error to be called, it must be one of the following scenarios:

The error is thrown synchronously inside a route guard function;

The error is caught and asynchronously handled by calling next(err) inside a route guard function;

An error occurred when trying to resolve an async component that is required to render a route.

Agree with @kwbskf here - the documentation could be more specific as to what's expected here.

For anyone else coming to this issue: I don't unfortunately have time right now to navigate the vue-router docs PR process, but I did track down the expected callback signature in router.d.ts:

type ErrorHandler = (err: Error) => void
onError(cb: ErrorHandler): void
Was this page helpful?
0 / 5 - 0 ratings

Related issues

Atinux picture Atinux  路  3Comments

achen224 picture achen224  路  3Comments

yyx990803 picture yyx990803  路  3Comments

kerlor picture kerlor  路  3Comments

posva picture posva  路  3Comments