From a8ced09350837d4931cc51957c29a2d44d0150d9 Mon Sep 17 00:00:00 2001 From: hazlank <401840614@qq.com> Date: Wed, 8 Sep 2021 20:39:01 +0800 Subject: [PATCH] feat: add constructor hint --- src/history/base.js | 4 +++- src/index.js | 3 +++ src/util/warn.js | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/history/base.js b/src/history/base.js index 5f2bad870..f96e4d9ce 100644 --- a/src/history/base.js +++ b/src/history/base.js @@ -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) } } diff --git a/src/index.js b/src/index.js index 3cf38a496..4ffe2db57 100644 --- a/src/index.js +++ b/src/index.js @@ -39,6 +39,9 @@ export default class VueRouter { afterHooks: Array 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 diff --git a/src/util/warn.js b/src/util/warn.js index 025d3b20f..95564c1a9 100644 --- a/src/util/warn.js +++ b/src/util/warn.js @@ -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}`) } }