]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
refactor: use warn
authorEduardo San Martin Morote <posva13@gmail.com>
Thu, 31 Jul 2025 16:04:36 +0000 (18:04 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Thu, 31 Jul 2025 16:04:36 +0000 (18:04 +0200)
packages/router/src/devtools.ts
packages/router/src/experimental/route-resolver/matchers/matcher-pattern.ts
packages/router/src/experimental/route-resolver/resolver-static.ts

index e4bef80d7892febc52abe87954735195b31cd356..f2511dce8f15ef2ffae18a0c7625894c06e05a7e 100644 (file)
@@ -18,6 +18,7 @@ import { UseLinkDevtoolsContext } from './RouterLink'
 import { RouterViewDevtoolsContext } from './RouterView'
 import { assign, isArray } from './utils'
 import { RouteLocationNormalized } from './typed-routes'
+import { warn } from './warning'
 
 /**
  * Copies a route location and removes any problematic properties that cannot be shown in devtools (e.g. Vue instances).
@@ -80,7 +81,7 @@ export function addDevtools(app: App, router: Router, matcher: RouterMatcher) {
     },
     api => {
       if (typeof api.now !== 'function') {
-        console.warn(
+        warn(
           '[Vue Router]: You seem to be using an outdated version of Vue Devtools. Are you still using the Beta release instead of the stable one? You can find the links at https://devtools.vuejs.org/guide/installation.html.'
         )
       }
index 399ba1b00cf78fd9cae87ec15b504acefa5b0fd5..f939aa571c3602ea92dc37e562bd75ddca698dbe 100644 (file)
@@ -1,3 +1,4 @@
+import { warn } from '../../../warning'
 import { decode, MatcherQueryParams } from '../resolver-abstract'
 import { miss } from './errors'
 
@@ -236,7 +237,7 @@ export class MatcherPatternPathDynamic<
     }
 
     if (__DEV__ && i !== match.length) {
-      console.warn(
+      warn(
         `Regexp matched ${match.length} params, but ${i} params are defined. Found when matching "${path}" against ${String(this.re)}`
       )
     }
index 4b7068be9b93cc8473e6777685fa85a11ca7d1a4..0b6efb26356824e19c5c7d5f837077cb917fd3e6 100644 (file)
@@ -22,6 +22,7 @@ import type {
   MatcherPatternQuery,
   MatcherPatternHash,
 } from './matchers/matcher-pattern'
+import { warn } from '../../warning'
 
 // TODO: find a better name than static that doesn't conflict with static params
 // maybe fixed or simple
@@ -151,7 +152,7 @@ export function createStaticResolver<
     if (typeof to === 'object' && (to.name || to.path == null)) {
       // relative location by path or by name
       if (__DEV__ && to.name == null && currentLocation == null) {
-        console.warn(
+        warn(
           `Cannot resolve relative location "${JSON.stringify(to)}"without a current location. This will throw in production.`,
           to
         )
@@ -175,8 +176,17 @@ export function createStaticResolver<
       // either one of them must be defined and is catched by the dev only warn above
       const name = to.name ?? currentLocation!.name
       const record = recordMap.get(name)!
-      if (__DEV__ && (!record || !name)) {
-        throw new Error(`Record "${String(name)}" not found`)
+
+      if (__DEV__) {
+        if (!record || !name) {
+          throw new Error(`Record "${String(name)}" not found`)
+        }
+
+        if (typeof to === 'object' && to.hash?.startsWith('#')) {
+          warn(
+            `A \`hash\` should always start with the character "#". Replace "${to.hash}" with "#${to.hash}".`
+          )
+        }
       }
 
       // unencoded params in a formatted form that the user came up with