Skip to content

Commit 28b769b

Browse files
authored
feat: add constructor hint (#3626)
1 parent 82684b4 commit 28b769b

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

src/history/base.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,9 @@ export class History {
146146
cb(err)
147147
})
148148
} else {
149-
warn(false, 'uncaught error during route navigation:')
149+
if (process.env.NODE_ENV !== 'production') {
150+
warn(false, 'uncaught error during route navigation:')
151+
}
150152
console.error(err)
151153
}
152154
}

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

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)