Skip to content

Commit dacd36d

Browse files
authored
fix(experimental): display location on its own line in VUE_ROUTER_R0129 (#2894)
1 parent ad70a67 commit dacd36d

4 files changed

Lines changed: 15 additions & 5 deletions

File tree

‎packages/router/src/diagnostics.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ export const diagnostics = /*#__PURE__*/ defineDiagnostics({
5050
fix: 'Return null from match() to skip a route, or call miss() in a param parser. Fix the thrown error if it is a bug.',
5151
},
5252
VUE_ROUTER_R0129: {
53-
why: (p: { location: string }) =>
54-
`Cannot resolve relative location ${p.location} without a "name": there is no current location, or the current location has no route. This crashes in production.`,
53+
why: (p: { location: Parameters<typeof stringifyRoute>[0] }) =>
54+
`Cannot resolve a relative location without a "name": there is no current location, or the current location has no route. This crashes in production.\nLocation: ${stringifyRoute(p.location)}`,
5555
fix: 'Pass the location it is relative to as the second argument of resolve(), or use a location with a "name" or an absolute "path".',
5656
},
5757
VUE_ROUTER_R0125: {

‎packages/router/src/errors.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,16 @@ const propertiesToLog = ['params', 'query', 'hash'] as const
199199
*
200200
* @internal
201201
*/
202-
export function stringifyRoute(to: RouteLocationRaw): string {
202+
export function stringifyRoute(
203+
to:
204+
| string
205+
| {
206+
path?: string | null
207+
params?: unknown
208+
query?: unknown
209+
hash?: unknown
210+
}
211+
): string {
203212
if (!to || typeof to === 'string') return to
204213
if (to.path != null) return to.path
205214
const location = {} as Record<string, unknown>

‎packages/router/src/experimental/route-resolver/resolver-fixed.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ export function createFixedResolver<
239239
to.name == null &&
240240
!(currentLocation && recordMap.has(currentLocation.name))
241241
) {
242-
diagnostics.VUE_ROUTER_R0129({ location: JSON.stringify(to) })
242+
diagnostics.VUE_ROUTER_R0129({ location: to })
243243
// NOTE: normally there is no query, hash or path but this helps debug
244244
// what kind of object location was passed
245245
const query = normalizeQuery(to.query)

‎packages/router/src/experimental/router.spec.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,8 @@ describe('Experimental Router', () => {
990990
})
991991
expect(router.resolve({ query: { page: ['2'] } }).matched).toEqual([])
992992
expect('VUE_ROUTER_R0129').toHaveBeenWarnedTimes(1)
993-
expect('Cannot resolve relative location').toHaveBeenWarned()
993+
expect('Cannot resolve a relative location').toHaveBeenWarned()
994+
expect('\nLocation: {\n "query"').toHaveBeenWarned()
994995
expect('No match found').toHaveBeenWarned()
995996
})
996997

0 commit comments

Comments
 (0)