@@ -70,9 +70,17 @@ import { addDevtools } from './devtools'
7070
7171/**
7272 * Internal type to define an ErrorHandler
73+ *
74+ * @param error - error thrown
75+ * @param to - location we were navigating to when the error happened
76+ * @param from - location we were navigating from when the error happened
7377 * @internal
7478 */
75- export type _ErrorHandler = ( error : any ) => any
79+ export type _ErrorHandler = (
80+ error : any ,
81+ to : RouteLocationNormalized ,
82+ from : RouteLocationNormalizedLoaded
83+ ) => any
7684// resolve, reject arguments of Promise constructor
7785type OnReadyCallback = [ ( ) => void , ( reason ?: any ) => void ]
7886
@@ -664,7 +672,7 @@ export function createRouter(options: RouterOptions): Router {
664672 isNavigationFailure ( error )
665673 ? error
666674 : // reject any unknown error
667- triggerError ( error )
675+ triggerError ( error , toLocation , from )
668676 )
669677 . then ( ( failure : NavigationFailure | NavigationRedirectError | void ) => {
670678 if ( failure ) {
@@ -979,7 +987,7 @@ export function createRouter(options: RouterOptions): Router {
979987 // do not restore history on unknown direction
980988 if ( info . delta ) routerHistory . go ( - info . delta , false )
981989 // unrecognized error, transfer to the global handler
982- return triggerError ( error )
990+ return triggerError ( error , toLocation , from )
983991 } )
984992 . then ( ( failure : NavigationFailure | void ) => {
985993 failure =
@@ -1012,14 +1020,21 @@ export function createRouter(options: RouterOptions): Router {
10121020
10131021 /**
10141022 * Trigger errorHandlers added via onError and throws the error as well
1023+ *
10151024 * @param error - error to throw
1025+ * @param to - location we were navigating to when the error happened
1026+ * @param from - location we were navigating from when the error happened
10161027 * @returns the error as a rejected promise
10171028 */
1018- function triggerError ( error : any ) : Promise < unknown > {
1029+ function triggerError (
1030+ error : any ,
1031+ to : RouteLocationNormalized ,
1032+ from : RouteLocationNormalizedLoaded
1033+ ) : Promise < unknown > {
10191034 markAsReady ( error )
10201035 const list = errorHandlers . list ( )
10211036 if ( list . length ) {
1022- list . forEach ( handler => handler ( error ) )
1037+ list . forEach ( handler => handler ( error , to , from ) )
10231038 } else {
10241039 if ( __DEV__ ) {
10251040 warn ( 'uncaught error during route navigation:' )
@@ -1072,7 +1087,7 @@ export function createRouter(options: RouterOptions): Router {
10721087 return nextTick ( )
10731088 . then ( ( ) => scrollBehavior ( to , from , scrollPosition ) )
10741089 . then ( position => position && scrollToPosition ( position ) )
1075- . catch ( triggerError )
1090+ . catch ( err => triggerError ( err , to , from ) )
10761091 }
10771092
10781093 const go = ( delta : number ) => routerHistory . go ( delta )
0 commit comments