Skip to content

Commit 9f5989e

Browse files
committed
refactor: isRouterError -> isNavigationFailure
1 parent b651040 commit 9f5989e

File tree

4 files changed

+21
-13
lines changed

4 files changed

+21
-13
lines changed

src/history/abstract.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import type Router from '../index'
44
import { History } from './base'
5-
import { NavigationFailureType, isRouterError } from '../util/errors'
5+
import { NavigationFailureType, isNavigationFailure } from '../util/errors'
66

77
export class AbstractHistory extends History {
88
index: number
@@ -50,7 +50,7 @@ export class AbstractHistory extends History {
5050
this.updateRoute(route)
5151
},
5252
err => {
53-
if (isRouterError(err, NavigationFailureType.duplicated)) {
53+
if (isNavigationFailure(err, NavigationFailureType.duplicated)) {
5454
this.index = targetIndex
5555
}
5656
}

src/history/base.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
createNavigationRedirectedError,
1818
createNavigationAbortedError,
1919
isError,
20-
isRouterError,
20+
isNavigationFailure,
2121
NavigationFailureType
2222
} from '../util/errors'
2323

@@ -37,7 +37,11 @@ export class History {
3737
// implemented by sub-classes
3838
+go: (n: number) => void
3939
+push: (loc: RawLocation, onComplete?: Function, onAbort?: Function) => void
40-
+replace: (loc: RawLocation, onComplete?: Function, onAbort?: Function) => void
40+
+replace: (
41+
loc: RawLocation,
42+
onComplete?: Function,
43+
onAbort?: Function
44+
) => void
4145
+ensureURL: (push?: boolean) => void
4246
+getCurrentLocation: () => string
4347
+setupListeners: Function
@@ -117,7 +121,7 @@ export class History {
117121
this.ready = true
118122
// Initial redirection should still trigger the onReady onSuccess
119123
// https://github.com/vuejs/vue-router/issues/3225
120-
if (!isRouterError(err, NavigationFailureType.redirected)) {
124+
if (!isNavigationFailure(err, NavigationFailureType.redirected)) {
121125
this.readyErrorCbs.forEach(cb => {
122126
cb(err)
123127
})
@@ -137,7 +141,7 @@ export class History {
137141
// changed after adding errors with
138142
// https://github.com/vuejs/vue-router/pull/3047 before that change,
139143
// redirect and aborted navigation would produce an err == null
140-
if (!isRouterError(err) && isError(err)) {
144+
if (!isNavigationFailure(err) && isError(err)) {
141145
if (this.errorCbs.length) {
142146
this.errorCbs.forEach(cb => {
143147
cb(err)

src/index.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ import { AbstractHistory } from './history/abstract'
1616

1717
import type { Matcher } from './create-matcher'
1818

19-
import { isRouterError, NavigationFailureType } from './util/errors'
19+
import { isNavigationFailure, NavigationFailureType } from './util/errors'
2020

2121
export default class VueRouter {
2222
static install: () => void
2323
static version: string
24-
static isRouterError: Function
24+
static isNavigationFailure: Function
2525
static NavigationFailureType: any
2626

2727
app: any
@@ -120,7 +120,7 @@ export default class VueRouter {
120120
const history = this.history
121121

122122
if (history instanceof HTML5History || history instanceof HashHistory) {
123-
const handleInitialScroll = (routeOrError) => {
123+
const handleInitialScroll = routeOrError => {
124124
const from = history.current
125125
const expectScroll = this.options.scrollBehavior
126126
const supportsScroll = supportsPushState && expectScroll
@@ -129,7 +129,7 @@ export default class VueRouter {
129129
handleScroll(this, routeOrError, from, false)
130130
}
131131
}
132-
const setupListeners = (routeOrError) => {
132+
const setupListeners = routeOrError => {
133133
history.setupListeners()
134134
handleInitialScroll(routeOrError)
135135
}
@@ -271,7 +271,7 @@ function createHref (base: string, fullPath: string, mode) {
271271

272272
VueRouter.install = install
273273
VueRouter.version = '__VERSION__'
274-
VueRouter.isRouterError = isRouterError
274+
VueRouter.isNavigationFailure = isNavigationFailure
275275
VueRouter.NavigationFailureType = NavigationFailureType
276276

277277
if (inBrowser && window.Vue) {

src/util/errors.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ export function isError (err) {
7676
return Object.prototype.toString.call(err).indexOf('Error') > -1
7777
}
7878

79-
export function isRouterError (err, errorType) {
80-
return isError(err) && err._isRouter && (errorType == null || err.type === errorType)
79+
export function isNavigationFailure (err, errorType) {
80+
return (
81+
isError(err) &&
82+
err._isRouter &&
83+
(errorType == null || err.type === errorType)
84+
)
8185
}

0 commit comments

Comments
 (0)