]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
feat(warn): warn when params are provided alongside path
authorEduardo San Martin Morote <posva13@gmail.com>
Fri, 1 May 2020 14:46:29 +0000 (16:46 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Fri, 1 May 2020 14:46:29 +0000 (16:46 +0200)
src/encoding.ts
src/history/html5.ts
src/matcher/index.ts
src/router.ts
src/scrollBehavior.ts
src/warning.ts [new file with mode: 0644]

index 2d87ecf2f139ecf61e55c6a09d79b6b28da0903e..c863c25e3467cec3668b0ef98560ed4dbb63fbc8 100644 (file)
@@ -1,4 +1,4 @@
-import { warn } from 'vue'
+import { warn } from './warning'
 
 /**
  * Encoding Rules ␣ = Space Path: ␣ " < > # ? { } Query: ␣ " < > # & = Hash: ␣ "
index 3a0ff3f3551b36af8c07bfc8e7cb475573b7f90e..e51378a7e6cf6d28ada50cf5a2bd224c17695ae3 100644 (file)
@@ -14,7 +14,7 @@ import {
   computeScrollPosition,
   ScrollPositionCoordinates,
 } from '../scrollBehavior'
-import { warn } from 'vue'
+import { warn } from '../warning'
 import { stripBase } from '../location'
 
 type PopStateListener = (this: Window, ev: PopStateEvent) => any
@@ -205,7 +205,7 @@ function useHistoryStateNavigation(base: string) {
       history[replace ? 'replaceState' : 'pushState'](state, '', url)
       historyState.value = state
     } catch (err) {
-      warn('[vue-router]: Error with push/replace State', err)
+      warn('Error with push/replace State', err)
       // Force the navigation, this also resets the call count
       window.location[replace ? 'replace' : 'assign'](url)
     }
index 0630b25fad5a1067c40d1a4f2a6fcf739c07a659..1b0d0da51b808c201c987a2defc38b348b0cac74 100644 (file)
@@ -14,7 +14,7 @@ import {
   PathParserOptions,
   _PathParserOptions,
 } from './pathParserRanker'
-import { warn } from 'vue'
+import { warn } from '../warning'
 
 let noop = () => {}
 
index 2795a42bb4ad2311806a741b0c9d33c876a279fc..8470fafb222d46438bfed6cb1f9015c7d8ae11f0 100644 (file)
@@ -38,11 +38,12 @@ import {
   parseQuery as originalParseQuery,
   stringifyQuery as originalStringifyQuery,
 } from './query'
-import { shallowRef, Ref, nextTick, App, warn } from 'vue'
+import { shallowRef, Ref, nextTick, App } from 'vue'
 import { RouteRecord, RouteRecordNormalized } from './matcher/types'
 import { parseURL, stringifyURL, isSameRouteLocation } from './location'
 import { extractComponentsGuards, guardToPromiseFn } from './navigationGuards'
 import { applyRouterPlugin } from './install'
+import { warn } from './warning'
 
 /**
  * Internal type to define an ErrorHandler
@@ -248,10 +249,14 @@ export function createRouter(options: RouterOptions): Router {
       }
     }
 
-    // TODO: dev warning if params and path at the same time
-
     // path could be relative in object as well
     if ('path' in rawLocation) {
+      if (__DEV__ && 'params' in rawLocation) {
+        warn(
+          // @ts-ignore
+          `Path "${rawLocation.path}" was passed with params but they will be ignored. Use a named route instead or build the path yourself`
+        )
+      }
       rawLocation = {
         ...rawLocation,
         path: parseURL(parseQuery, rawLocation.path, currentLocation.path).path,
index c0fe79f4644db4e1b9a5e81464a601121d0abfac..f0c69c040789009f635a032f81f9d25ad5178d7f 100644 (file)
@@ -1,5 +1,5 @@
 import { RouteLocationNormalized, RouteLocationNormalizedLoaded } from './types'
-import { warn } from 'vue'
+import { warn } from './warning'
 
 export type ScrollPositionCoordinates = {
   /**
diff --git a/src/warning.ts b/src/warning.ts
new file mode 100644 (file)
index 0000000..9b1c653
--- /dev/null
@@ -0,0 +1,12 @@
+import { warn as vueWarn } from 'vue'
+
+const originalWarn = console.warn
+function customWarn(msg: string, ...args: any[]) {
+  originalWarn(msg.replace('Vue warn', 'Vue Router warn'), ...args)
+}
+
+export function warn(msg: string, ...args: any[]) {
+  console.warn = customWarn
+  vueWarn(msg, ...args)
+  console.warn = originalWarn
+}