@@ -4,14 +4,20 @@ import { _Vue } from '../install'
44import type Router from '../index'
55import { inBrowser } from '../util/dom'
66import { runQueue } from '../util/async'
7- import { warn , isError , isExtendedError } from '../util/warn'
7+ import { warn , isError , isRouterError } from '../util/warn'
88import { START , isSameRoute } from '../util/route'
99import {
1010 flatten ,
1111 flatMapComponents ,
1212 resolveAsyncComponents
1313} from '../util/resolve-components'
14- import { NavigationDuplicated } from './errors'
14+ import {
15+ createNavigationDuplicatedError ,
16+ createNavigationCancelledError ,
17+ createNavigationRedirectedError ,
18+ createNavigationAbortedError ,
19+ NavigationFailureType
20+ } from './errors'
1521
1622export class History {
1723 router : Router
@@ -108,7 +114,7 @@ export class History {
108114 // When the user navigates through history through back/forward buttons
109115 // we do not want to throw the error. We only throw it if directly calling
110116 // push/replace. That's why it's not included in isError
111- if ( ! isExtendedError ( NavigationDuplicated , err ) && isError ( err ) ) {
117+ if ( ! isRouterError ( err , NavigationFailureType . NAVIGATION_DUPLICATED ) && isError ( err ) ) {
112118 if ( this . errorCbs . length ) {
113119 this . errorCbs . forEach ( cb => {
114120 cb ( err )
@@ -126,7 +132,7 @@ export class History {
126132 route . matched . length === current . matched . length
127133 ) {
128134 this . ensureURL ( )
129- return abort ( new NavigationDuplicated ( route ) )
135+ return abort ( createNavigationDuplicatedError ( current , route ) )
130136 }
131137
132138 const { updated, deactivated, activated } = resolveQueue (
@@ -150,12 +156,15 @@ export class History {
150156 this . pending = route
151157 const iterator = ( hook : NavigationGuard , next ) => {
152158 if ( this . pending !== route ) {
153- return abort ( )
159+ return abort ( createNavigationCancelledError ( current , route ) )
154160 }
155161 try {
156162 hook ( route , current , ( to : any ) => {
157- if ( to === false || isError ( to ) ) {
163+ if ( to === false ) {
158164 // next(false) -> abort navigation, ensure current URL
165+ this . ensureURL ( true )
166+ abort ( createNavigationAbortedError ( current , route ) )
167+ } else if ( isError ( to ) ) {
159168 this . ensureURL ( true )
160169 abort ( to )
161170 } else if (
@@ -164,7 +173,7 @@ export class History {
164173 ( typeof to . path === 'string' || typeof to . name === 'string' ) )
165174 ) {
166175 // next('/') or next({ path: '/' }) -> redirect
167- abort ( )
176+ abort ( createNavigationRedirectedError ( current , route ) )
168177 if ( typeof to === 'object' && to . replace ) {
169178 this . replace ( to )
170179 } else {
0 commit comments