Skip to content

Commit

Permalink
feat: add constructor hint (#3626)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hazlank authored Oct 3, 2021
1 parent 82684b4 commit 28b769b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/history/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ export class History {
cb(err)
})
} else {
warn(false, 'uncaught error during route navigation:')
if (process.env.NODE_ENV !== 'production') {
warn(false, 'uncaught error during route navigation:')
}
console.error(err)
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ export default class VueRouter {
afterHooks: Array<?AfterNavigationHook>

constructor (options: RouterOptions = {}) {
if (process.env.NODE_ENV !== 'production') {
warn(this instanceof VueRouter, `Router must be called with the new operator.`)
}
this.app = null
this.apps = []
this.options = options
Expand Down
2 changes: 1 addition & 1 deletion src/util/warn.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function assert (condition: any, message: string) {
}

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

0 comments on commit 28b769b

Please sign in to comment.