@@ -83,6 +83,7 @@ import {
83
83
routerKey ,
84
84
routerViewLocationKey ,
85
85
} from '../injectionSymbols'
86
+ import { MatcherLocationAsPathAbsolute } from '../new-route-resolver/matcher-location'
86
87
87
88
/**
88
89
* resolve, reject arguments of Promise constructor
@@ -406,6 +407,11 @@ export interface EXPERIMENTAL_RouteRecordRaw extends NEW_MatcherRecordRaw {
406
407
* Arbitrary data attached to the record.
407
408
*/
408
409
meta ?: RouteMeta
410
+
411
+ components ?: Record < string , unknown >
412
+ component ?: unknown
413
+
414
+ redirect ?: unknown
409
415
}
410
416
411
417
// TODO: is it worth to have 2 types for the undefined values?
@@ -510,6 +516,15 @@ export function experimental_createRouter(
510
516
return ! ! matcher . getMatcher ( name )
511
517
}
512
518
519
+ function locationAsObject (
520
+ to : RouteLocationRaw | RouteLocationNormalized ,
521
+ currentLocation : string = currentRoute . value . path
522
+ ) : Exclude < RouteLocationRaw , string > | RouteLocationNormalized {
523
+ return typeof to === 'string'
524
+ ? parseURL ( parseQuery , to , currentLocation )
525
+ : to
526
+ }
527
+
513
528
function resolve (
514
529
rawLocation : RouteLocationRaw ,
515
530
currentLocation ?: RouteLocationNormalizedLoaded
@@ -522,6 +537,11 @@ export function experimental_createRouter(
522
537
currentLocation && assign ( { } , currentLocation || currentRoute . value )
523
538
// currentLocation = assign({}, currentLocation || currentRoute.value)
524
539
540
+ const locationObject = locationAsObject (
541
+ rawLocation ,
542
+ currentRoute . value . path
543
+ )
544
+
525
545
if ( __DEV__ ) {
526
546
if ( ! isRouteLocation ( rawLocation ) ) {
527
547
warn (
@@ -531,12 +551,9 @@ export function experimental_createRouter(
531
551
return resolve ( { } )
532
552
}
533
553
534
- if (
535
- typeof rawLocation === 'object' &&
536
- ! rawLocation . hash ?. startsWith ( '#' )
537
- ) {
554
+ if ( ! locationObject . hash ?. startsWith ( '#' ) ) {
538
555
warn (
539
- `A \`hash\` should always start with the character "#". Replace "${ rawLocation . hash } " with "#${ rawLocation . hash } ".`
556
+ `A \`hash\` should always start with the character "#". Replace "${ locationObject . hash } " with "#${ locationObject . hash } ".`
540
557
)
541
558
}
542
559
}
@@ -555,16 +572,20 @@ export function experimental_createRouter(
555
572
556
573
const matchedRoute = matcher . resolve (
557
574
// FIXME: should be ok
558
- // @ts -expect-error: too many overlads
559
- rawLocation ,
560
- currentLocation
575
+ // locationObject as MatcherLocationAsPathRelative,
576
+ // locationObject as MatcherLocationAsRelative,
577
+ // locationObject as MatcherLocationAsName, // TODO: this one doesn't allow an undefined currentLocation, the other ones work
578
+ locationObject as MatcherLocationAsPathAbsolute ,
579
+ currentLocation as unknown as NEW_LocationResolved < EXPERIMENTAL_RouteRecordNormalized >
561
580
)
562
581
const href = routerHistory . createHref ( matchedRoute . fullPath )
563
582
564
583
if ( __DEV__ ) {
565
584
if ( href . startsWith ( '//' ) ) {
566
585
warn (
567
- `Location "${ rawLocation } " resolved to "${ href } ". A resolved location cannot start with multiple slashes.`
586
+ `Location ${ JSON . stringify (
587
+ rawLocation
588
+ ) } resolved to "${ href } ". A resolved location cannot start with multiple slashes.`
568
589
)
569
590
}
570
591
if ( ! matchedRoute . matched . length ) {
@@ -581,14 +602,6 @@ export function experimental_createRouter(
581
602
} )
582
603
}
583
604
584
- function locationAsObject (
585
- to : RouteLocationRaw | RouteLocationNormalized
586
- ) : Exclude < RouteLocationRaw , string > | RouteLocationNormalized {
587
- return typeof to === 'string'
588
- ? parseURL ( parseQuery , to , currentRoute . value . path )
589
- : assign ( { } , to )
590
- }
591
-
592
605
function checkCanceledNavigation (
593
606
to : RouteLocationNormalized ,
594
607
from : RouteLocationNormalized
0 commit comments