Skip to content

Commit 93dae28

Browse files
committed
feat: add constructor hint
1 parent e4fe767 commit 93dae28

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

Diff for: src/history/base.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,10 @@ export class History {
146146
cb(err)
147147
})
148148
} else {
149-
warn(false, 'uncaught error during route navigation:')
150-
console.error(err)
149+
if (process.env.NODE_ENV !== 'production') {
150+
warn(false, 'uncaught error during route navigation:')
151+
console.error(err)
152+
}
151153
}
152154
}
153155
onAbort && onAbort(err)

Diff for: src/index.js

+3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ export default class VueRouter {
3939
afterHooks: Array<?AfterNavigationHook>
4040

4141
constructor (options: RouterOptions = {}) {
42+
if (process.env.NODE_ENV !== 'production') {
43+
warn(this instanceof VueRouter, `Router must be called with the new operator.`)
44+
}
4245
this.app = null
4346
this.apps = []
4447
this.options = options

Diff for: src/util/warn.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export function assert (condition: any, message: string) {
77
}
88

99
export function warn (condition: any, message: string) {
10-
if (process.env.NODE_ENV !== 'production' && !condition) {
10+
if (!condition) {
1111
typeof console !== 'undefined' && console.warn(`[vue-router] ${message}`)
1212
}
1313
}

0 commit comments

Comments
 (0)