1- import { type LocationQuery , normalizeQuery , stringifyQuery } from '../query'
1+ import {
2+ type LocationQuery ,
3+ normalizeQuery ,
4+ parseQuery ,
5+ stringifyQuery ,
6+ } from '../query'
27import type {
38 MatcherPatternHash ,
49 MatcherPatternPath ,
510 MatcherPatternQuery ,
611} from './matcher-pattern'
712import { warn } from '../warning'
813import { encodeQueryValue as _encodeQueryValue , encodeParam } from '../encoding'
9- import { NEW_stringifyURL , resolveRelativePath } from '../location'
14+ import {
15+ LocationNormalized ,
16+ NEW_stringifyURL ,
17+ parseURL ,
18+ resolveRelativePath ,
19+ } from '../location'
1020import type {
1121 MatcherLocationAsNamed ,
1222 MatcherLocationAsPathAbsolute ,
@@ -32,19 +42,19 @@ export interface NEW_RouterResolver<TMatcherRecordRaw, TMatcherRecord> {
3242 /**
3343 * Resolves an absolute location (like `/path/to/somewhere`).
3444 */
35- // resolve(
36- // absoluteLocation: `/${string}`,
37- // currentLocation?: undefined | NEW_LocationResolved<TMatcherRecord>
38- // ): NEW_LocationResolved<TMatcherRecord>
45+ resolve (
46+ absoluteLocation : `/${string } `,
47+ currentLocation ?: undefined
48+ ) : NEW_LocationResolved < TMatcherRecord >
3949
4050 /**
4151 * Resolves a string location relative to another location. A relative location can be `./same-folder`,
4252 * `../parent-folder`, `same-folder`, or even `?page=2`.
4353 */
44- // resolve(
45- // relativeLocation: string,
46- // currentLocation: NEW_LocationResolved<TMatcherRecord>
47- // ): NEW_LocationResolved<TMatcherRecord>
54+ resolve (
55+ relativeLocation : string ,
56+ currentLocation : NEW_LocationResolved < TMatcherRecord >
57+ ) : NEW_LocationResolved < TMatcherRecord >
4858
4959 /**
5060 * Resolves a location by its name. Any required params or query must be passed in the `options` argument.
@@ -53,6 +63,7 @@ export interface NEW_RouterResolver<TMatcherRecordRaw, TMatcherRecord> {
5363 location : MatcherLocationAsNamed ,
5464 // TODO: is this useful?
5565 currentLocation ?: undefined
66+ // currentLocation?: undefined | NEW_LocationResolved<TMatcherRecord>
5667 ) : NEW_LocationResolved < TMatcherRecord >
5768
5869 /**
@@ -63,7 +74,7 @@ export interface NEW_RouterResolver<TMatcherRecordRaw, TMatcherRecord> {
6374 location : MatcherLocationAsPathAbsolute ,
6475 // TODO: is this useful?
6576 currentLocation ?: undefined
66- // currentLocation?: NEW_LocationResolved<TMatcherRecord>
77+ // currentLocation?: NEW_LocationResolved<TMatcherRecord> | undefined
6778 ) : NEW_LocationResolved < TMatcherRecord >
6879
6980 resolve (
@@ -121,7 +132,7 @@ export interface NEW_RouterResolver<TMatcherRecordRaw, TMatcherRecord> {
121132 */
122133export type MatcherLocationRaw =
123134 // | `/${string}`
124- // | string
135+ | string
125136 | MatcherLocationAsNamed
126137 | MatcherLocationAsPathAbsolute
127138 | MatcherLocationAsPathRelative
@@ -355,23 +366,27 @@ export function createCompiledMatcher<
355366
356367 // NOTE: because of the overloads, we need to manually type the arguments
357368 type MatcherResolveArgs =
358- // | [
359- // absoluteLocation: `/${string}`,
360- // currentLocation?: undefined | NEW_LocationResolved<TMatcherRecord>
361- // ]
362- // | [
363- // relativeLocation: string,
364- // currentLocation: NEW_LocationResolved<TMatcherRecord>
365- // ]
369+ | [ absoluteLocation : `/${string } `, currentLocation ?: undefined ]
370+ | [
371+ relativeLocation : string ,
372+ currentLocation : NEW_LocationResolved < TMatcherRecord >
373+ ]
366374 | [
367375 absoluteLocation : MatcherLocationAsPathAbsolute ,
376+ // Same as above
377+ // currentLocation?: NEW_LocationResolved<TMatcherRecord> | undefined
368378 currentLocation ?: undefined
369379 ]
370380 | [
371381 relativeLocation : MatcherLocationAsPathRelative ,
372382 currentLocation : NEW_LocationResolved < TMatcherRecord >
373383 ]
374- | [ location : MatcherLocationAsNamed , currentLocation ?: undefined ]
384+ | [
385+ location : MatcherLocationAsNamed ,
386+ // Same as above
387+ // currentLocation?: NEW_LocationResolved<TMatcherRecord> | undefined
388+ currentLocation ?: undefined
389+ ]
375390 | [
376391 relativeLocation : MatcherLocationAsRelative ,
377392 currentLocation : NEW_LocationResolved < TMatcherRecord >
@@ -382,7 +397,7 @@ export function createCompiledMatcher<
382397 ) : NEW_LocationResolved < TMatcherRecord > {
383398 const [ to , currentLocation ] = args
384399
385- if ( to . name || to . path == null ) {
400+ if ( typeof to === 'object' && ( to . name || to . path == null ) ) {
386401 // relative location or by name
387402 if ( __DEV__ && to . name == null && currentLocation == null ) {
388403 console . warn (
@@ -442,13 +457,17 @@ export function createCompiledMatcher<
442457 // string location, e.g. '/foo', '../bar', 'baz', '?page=1'
443458 } else {
444459 // parseURL handles relative paths
445- // parseURL(to.path, currentLocation?.path)
446- const query = normalizeQuery ( to . query )
447- const url = {
448- fullPath : NEW_stringifyURL ( stringifyQuery , to . path , query , to . hash ) ,
449- path : resolveRelativePath ( to . path , currentLocation ?. path || '/' ) ,
450- query,
451- hash : to . hash || '' ,
460+ let url : LocationNormalized
461+ if ( typeof to === 'string' ) {
462+ url = parseURL ( parseQuery , to , currentLocation ?. path )
463+ } else {
464+ const query = normalizeQuery ( to . query )
465+ url = {
466+ fullPath : NEW_stringifyURL ( stringifyQuery , to . path , query , to . hash ) ,
467+ path : resolveRelativePath ( to . path , currentLocation ?. path || '/' ) ,
468+ query,
469+ hash : to . hash || '' ,
470+ }
452471 }
453472
454473 let matcher : TMatcherRecord | undefined
0 commit comments