@remix-run/router 0.0.0-experimental-35fa15e5 → 0.0.0-experimental-8bb3ffdf
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +200 -0
- package/README.md +1 -1
- package/dist/router.cjs.js +124 -103
- package/dist/router.cjs.js.map +1 -1
- package/dist/router.d.ts +8 -0
- package/dist/router.js +115 -98
- package/dist/router.js.map +1 -1
- package/dist/router.umd.js +124 -103
- package/dist/router.umd.js.map +1 -1
- package/dist/router.umd.min.js +2 -2
- package/dist/router.umd.min.js.map +1 -1
- package/dist/utils.d.ts +1 -1
- package/package.json +1 -1
- package/router.ts +118 -78
- package/utils.ts +18 -30
package/dist/utils.d.ts
CHANGED
|
@@ -401,7 +401,7 @@ export declare function resolvePath(to: To, fromPathname?: string): Path;
|
|
|
401
401
|
* </Route>
|
|
402
402
|
*/
|
|
403
403
|
export declare function getPathContributingMatches<T extends AgnosticRouteMatch = AgnosticRouteMatch>(matches: T[]): T[];
|
|
404
|
-
export declare function getResolveToMatches<T extends AgnosticRouteMatch = AgnosticRouteMatch>(matches: T[]): string[];
|
|
404
|
+
export declare function getResolveToMatches<T extends AgnosticRouteMatch = AgnosticRouteMatch>(matches: T[], v7_relativeSplatPath: boolean): string[];
|
|
405
405
|
/**
|
|
406
406
|
* @private
|
|
407
407
|
*/
|
package/package.json
CHANGED
package/router.ts
CHANGED
|
@@ -356,6 +356,7 @@ export interface FutureConfig {
|
|
|
356
356
|
v7_normalizeFormMethod: boolean;
|
|
357
357
|
v7_partialHydration: boolean;
|
|
358
358
|
v7_prependBasename: boolean;
|
|
359
|
+
v7_relativeSplatPath: boolean;
|
|
359
360
|
}
|
|
360
361
|
|
|
361
362
|
/**
|
|
@@ -781,6 +782,7 @@ export function createRouter(init: RouterInit): Router {
|
|
|
781
782
|
v7_normalizeFormMethod: false,
|
|
782
783
|
v7_partialHydration: false,
|
|
783
784
|
v7_prependBasename: false,
|
|
785
|
+
v7_relativeSplatPath: false,
|
|
784
786
|
...init.future,
|
|
785
787
|
};
|
|
786
788
|
// Cleanup function for history
|
|
@@ -815,19 +817,34 @@ export function createRouter(init: RouterInit): Router {
|
|
|
815
817
|
initialErrors = { [route.id]: error };
|
|
816
818
|
}
|
|
817
819
|
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
// as deep as we have data for and detect the nearest ancestor HydrateFallback
|
|
823
|
-
let initialized =
|
|
824
|
-
future.v7_partialHydration ||
|
|
820
|
+
let initialized: boolean;
|
|
821
|
+
let hasLazyRoutes = initialMatches.some((m) => m.route.lazy);
|
|
822
|
+
let hasLoaders = initialMatches.some((m) => m.route.loader);
|
|
823
|
+
if (hasLazyRoutes) {
|
|
825
824
|
// All initialMatches need to be loaded before we're ready. If we have lazy
|
|
826
825
|
// functions around still then we'll need to run them in initialize()
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
826
|
+
initialized = false;
|
|
827
|
+
} else if (!hasLoaders) {
|
|
828
|
+
// If we've got no loaders to run, then we're good to go
|
|
829
|
+
initialized = true;
|
|
830
|
+
} else if (future.v7_partialHydration) {
|
|
831
|
+
// If partial hydration is enabled, we're initialized so long as we were
|
|
832
|
+
// provided with hydrationData for every route with a loader, and no loaders
|
|
833
|
+
// were marked for explicit hydration
|
|
834
|
+
let loaderData = init.hydrationData ? init.hydrationData.loaderData : null;
|
|
835
|
+
let errors = init.hydrationData ? init.hydrationData.errors : null;
|
|
836
|
+
initialized = initialMatches.every(
|
|
837
|
+
(m) =>
|
|
838
|
+
m.route.loader &&
|
|
839
|
+
m.route.loader.hydrate !== true &&
|
|
840
|
+
((loaderData && loaderData[m.route.id] !== undefined) ||
|
|
841
|
+
(errors && errors[m.route.id] !== undefined))
|
|
842
|
+
);
|
|
843
|
+
} else {
|
|
844
|
+
// Without partial hydration - we're initialized if we were provided any
|
|
845
|
+
// hydrationData - which is expected to be complete
|
|
846
|
+
initialized = init.hydrationData != null;
|
|
847
|
+
}
|
|
831
848
|
|
|
832
849
|
let router: Router;
|
|
833
850
|
let state: RouterState = {
|
|
@@ -1008,11 +1025,7 @@ export function createRouter(init: RouterInit): Router {
|
|
|
1008
1025
|
// in the normal navigation flow. For SSR it's expected that lazy modules are
|
|
1009
1026
|
// resolved prior to router creation since we can't go into a fallbackElement
|
|
1010
1027
|
// UI for SSR'd apps
|
|
1011
|
-
if (
|
|
1012
|
-
!state.initialized ||
|
|
1013
|
-
(future.v7_partialHydration &&
|
|
1014
|
-
state.matches.some((m) => isUnhydratedRoute(state, m.route)))
|
|
1015
|
-
) {
|
|
1028
|
+
if (!state.initialized) {
|
|
1016
1029
|
startNavigation(HistoryAction.Pop, state.location, {
|
|
1017
1030
|
initialHydration: true,
|
|
1018
1031
|
});
|
|
@@ -1255,6 +1268,7 @@ export function createRouter(init: RouterInit): Router {
|
|
|
1255
1268
|
basename,
|
|
1256
1269
|
future.v7_prependBasename,
|
|
1257
1270
|
to,
|
|
1271
|
+
future.v7_relativeSplatPath,
|
|
1258
1272
|
opts?.fromRouteId,
|
|
1259
1273
|
opts?.relative
|
|
1260
1274
|
);
|
|
@@ -1571,7 +1585,8 @@ export function createRouter(init: RouterInit): Router {
|
|
|
1571
1585
|
matches,
|
|
1572
1586
|
manifest,
|
|
1573
1587
|
mapRouteProperties,
|
|
1574
|
-
basename
|
|
1588
|
+
basename,
|
|
1589
|
+
future.v7_relativeSplatPath
|
|
1575
1590
|
);
|
|
1576
1591
|
|
|
1577
1592
|
if (request.signal.aborted) {
|
|
@@ -1857,6 +1872,7 @@ export function createRouter(init: RouterInit): Router {
|
|
|
1857
1872
|
basename,
|
|
1858
1873
|
future.v7_prependBasename,
|
|
1859
1874
|
href,
|
|
1875
|
+
future.v7_relativeSplatPath,
|
|
1860
1876
|
routeId,
|
|
1861
1877
|
opts?.relative
|
|
1862
1878
|
);
|
|
@@ -1963,7 +1979,8 @@ export function createRouter(init: RouterInit): Router {
|
|
|
1963
1979
|
requestMatches,
|
|
1964
1980
|
manifest,
|
|
1965
1981
|
mapRouteProperties,
|
|
1966
|
-
basename
|
|
1982
|
+
basename,
|
|
1983
|
+
future.v7_relativeSplatPath
|
|
1967
1984
|
);
|
|
1968
1985
|
|
|
1969
1986
|
if (fetchRequest.signal.aborted) {
|
|
@@ -1975,33 +1992,39 @@ export function createRouter(init: RouterInit): Router {
|
|
|
1975
1992
|
return;
|
|
1976
1993
|
}
|
|
1977
1994
|
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
if (isRedirectResult(actionResult)) {
|
|
1984
|
-
fetchControllers.delete(key);
|
|
1985
|
-
if (pendingNavigationLoadId > originatingLoadId) {
|
|
1986
|
-
// A new navigation was kicked off after our action started, so that
|
|
1987
|
-
// should take precedence over this redirect navigation. We already
|
|
1988
|
-
// set isRevalidationRequired so all loaders for the new route should
|
|
1989
|
-
// fire unless opted out via shouldRevalidate
|
|
1995
|
+
// When using v7_fetcherPersist, we don't want errors bubbling up to the UI
|
|
1996
|
+
// or redirects processed for unmounted fetchers so we just revert them to
|
|
1997
|
+
// idle
|
|
1998
|
+
if (future.v7_fetcherPersist && deletedFetchers.has(key)) {
|
|
1999
|
+
if (isRedirectResult(actionResult) || isErrorResult(actionResult)) {
|
|
1990
2000
|
updateFetcherState(key, getDoneFetcher(undefined));
|
|
1991
2001
|
return;
|
|
1992
|
-
} else {
|
|
1993
|
-
fetchRedirectIds.add(key);
|
|
1994
|
-
updateFetcherState(key, getLoadingFetcher(submission));
|
|
1995
|
-
return startRedirectNavigation(state, actionResult, {
|
|
1996
|
-
fetcherSubmission: submission,
|
|
1997
|
-
});
|
|
1998
2002
|
}
|
|
1999
|
-
|
|
2003
|
+
// Let SuccessResult's fall through for revalidation
|
|
2004
|
+
} else {
|
|
2005
|
+
if (isRedirectResult(actionResult)) {
|
|
2006
|
+
fetchControllers.delete(key);
|
|
2007
|
+
if (pendingNavigationLoadId > originatingLoadId) {
|
|
2008
|
+
// A new navigation was kicked off after our action started, so that
|
|
2009
|
+
// should take precedence over this redirect navigation. We already
|
|
2010
|
+
// set isRevalidationRequired so all loaders for the new route should
|
|
2011
|
+
// fire unless opted out via shouldRevalidate
|
|
2012
|
+
updateFetcherState(key, getDoneFetcher(undefined));
|
|
2013
|
+
return;
|
|
2014
|
+
} else {
|
|
2015
|
+
fetchRedirectIds.add(key);
|
|
2016
|
+
updateFetcherState(key, getLoadingFetcher(submission));
|
|
2017
|
+
return startRedirectNavigation(state, actionResult, {
|
|
2018
|
+
fetcherSubmission: submission,
|
|
2019
|
+
});
|
|
2020
|
+
}
|
|
2021
|
+
}
|
|
2000
2022
|
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2023
|
+
// Process any non-redirect errors thrown
|
|
2024
|
+
if (isErrorResult(actionResult)) {
|
|
2025
|
+
setFetcherError(key, routeId, actionResult.error);
|
|
2026
|
+
return;
|
|
2027
|
+
}
|
|
2005
2028
|
}
|
|
2006
2029
|
|
|
2007
2030
|
if (isDeferredResult(actionResult)) {
|
|
@@ -2207,7 +2230,8 @@ export function createRouter(init: RouterInit): Router {
|
|
|
2207
2230
|
matches,
|
|
2208
2231
|
manifest,
|
|
2209
2232
|
mapRouteProperties,
|
|
2210
|
-
basename
|
|
2233
|
+
basename,
|
|
2234
|
+
future.v7_relativeSplatPath
|
|
2211
2235
|
);
|
|
2212
2236
|
|
|
2213
2237
|
// Deferred isn't supported for fetcher loads, await everything and treat it
|
|
@@ -2230,6 +2254,8 @@ export function createRouter(init: RouterInit): Router {
|
|
|
2230
2254
|
return;
|
|
2231
2255
|
}
|
|
2232
2256
|
|
|
2257
|
+
// We don't want errors bubbling up or redirects followed for unmounted
|
|
2258
|
+
// fetchers, so short circuit here if it was removed from the UI
|
|
2233
2259
|
if (deletedFetchers.has(key)) {
|
|
2234
2260
|
updateFetcherState(key, getDoneFetcher(undefined));
|
|
2235
2261
|
return;
|
|
@@ -2403,7 +2429,8 @@ export function createRouter(init: RouterInit): Router {
|
|
|
2403
2429
|
matches,
|
|
2404
2430
|
manifest,
|
|
2405
2431
|
mapRouteProperties,
|
|
2406
|
-
basename
|
|
2432
|
+
basename,
|
|
2433
|
+
future.v7_relativeSplatPath
|
|
2407
2434
|
)
|
|
2408
2435
|
),
|
|
2409
2436
|
...fetchersToLoad.map((f) => {
|
|
@@ -2415,7 +2442,8 @@ export function createRouter(init: RouterInit): Router {
|
|
|
2415
2442
|
f.matches,
|
|
2416
2443
|
manifest,
|
|
2417
2444
|
mapRouteProperties,
|
|
2418
|
-
basename
|
|
2445
|
+
basename,
|
|
2446
|
+
future.v7_relativeSplatPath
|
|
2419
2447
|
);
|
|
2420
2448
|
} else {
|
|
2421
2449
|
let error: ErrorResult = {
|
|
@@ -2801,6 +2829,13 @@ export function createRouter(init: RouterInit): Router {
|
|
|
2801
2829
|
|
|
2802
2830
|
export const UNSAFE_DEFERRED_SYMBOL = Symbol("deferred");
|
|
2803
2831
|
|
|
2832
|
+
/**
|
|
2833
|
+
* Future flags to toggle new feature behavior
|
|
2834
|
+
*/
|
|
2835
|
+
export interface StaticHandlerFutureConfig {
|
|
2836
|
+
v7_relativeSplatPath: boolean;
|
|
2837
|
+
}
|
|
2838
|
+
|
|
2804
2839
|
export interface CreateStaticHandlerOptions {
|
|
2805
2840
|
basename?: string;
|
|
2806
2841
|
/**
|
|
@@ -2808,6 +2843,7 @@ export interface CreateStaticHandlerOptions {
|
|
|
2808
2843
|
*/
|
|
2809
2844
|
detectErrorBoundary?: DetectErrorBoundaryFunction;
|
|
2810
2845
|
mapRouteProperties?: MapRoutePropertiesFunction;
|
|
2846
|
+
future?: Partial<StaticHandlerFutureConfig>;
|
|
2811
2847
|
}
|
|
2812
2848
|
|
|
2813
2849
|
export function createStaticHandler(
|
|
@@ -2833,6 +2869,11 @@ export function createStaticHandler(
|
|
|
2833
2869
|
} else {
|
|
2834
2870
|
mapRouteProperties = defaultMapRouteProperties;
|
|
2835
2871
|
}
|
|
2872
|
+
// Config driven behavior flags
|
|
2873
|
+
let future: StaticHandlerFutureConfig = {
|
|
2874
|
+
v7_relativeSplatPath: false,
|
|
2875
|
+
...(opts ? opts.future : null),
|
|
2876
|
+
};
|
|
2836
2877
|
|
|
2837
2878
|
let dataRoutes = convertRoutesToDataRoutes(
|
|
2838
2879
|
routes,
|
|
@@ -3095,6 +3136,7 @@ export function createStaticHandler(
|
|
|
3095
3136
|
manifest,
|
|
3096
3137
|
mapRouteProperties,
|
|
3097
3138
|
basename,
|
|
3139
|
+
future.v7_relativeSplatPath,
|
|
3098
3140
|
{ isStaticRequest: true, isRouteRequest, requestContext }
|
|
3099
3141
|
);
|
|
3100
3142
|
|
|
@@ -3263,6 +3305,7 @@ export function createStaticHandler(
|
|
|
3263
3305
|
manifest,
|
|
3264
3306
|
mapRouteProperties,
|
|
3265
3307
|
basename,
|
|
3308
|
+
future.v7_relativeSplatPath,
|
|
3266
3309
|
{ isStaticRequest: true, isRouteRequest, requestContext }
|
|
3267
3310
|
)
|
|
3268
3311
|
),
|
|
@@ -3353,6 +3396,7 @@ function normalizeTo(
|
|
|
3353
3396
|
basename: string,
|
|
3354
3397
|
prependBasename: boolean,
|
|
3355
3398
|
to: To | null,
|
|
3399
|
+
v7_relativeSplatPath: boolean,
|
|
3356
3400
|
fromRouteId?: string,
|
|
3357
3401
|
relative?: RelativeRoutingType
|
|
3358
3402
|
) {
|
|
@@ -3377,7 +3421,7 @@ function normalizeTo(
|
|
|
3377
3421
|
// Resolve the relative path
|
|
3378
3422
|
let path = resolveTo(
|
|
3379
3423
|
to ? to : ".",
|
|
3380
|
-
getResolveToMatches(contextualMatches),
|
|
3424
|
+
getResolveToMatches(contextualMatches, v7_relativeSplatPath),
|
|
3381
3425
|
stripBasename(location.pathname, basename) || location.pathname,
|
|
3382
3426
|
relative === "path"
|
|
3383
3427
|
);
|
|
@@ -3611,21 +3655,27 @@ function getMatchesToLoad(
|
|
|
3611
3655
|
let boundaryMatches = getLoaderMatchesUntilBoundary(matches, boundaryId);
|
|
3612
3656
|
|
|
3613
3657
|
let navigationMatches = boundaryMatches.filter((match, index) => {
|
|
3614
|
-
|
|
3615
|
-
|
|
3616
|
-
// call the unhydrated loaders
|
|
3617
|
-
return isUnhydratedRoute(state, match.route);
|
|
3618
|
-
}
|
|
3619
|
-
|
|
3620
|
-
if (match.route.lazy) {
|
|
3658
|
+
let { route } = match;
|
|
3659
|
+
if (route.lazy) {
|
|
3621
3660
|
// We haven't loaded this route yet so we don't know if it's got a loader!
|
|
3622
3661
|
return true;
|
|
3623
3662
|
}
|
|
3624
3663
|
|
|
3625
|
-
if (
|
|
3664
|
+
if (route.loader == null) {
|
|
3626
3665
|
return false;
|
|
3627
3666
|
}
|
|
3628
3667
|
|
|
3668
|
+
if (isInitialLoad) {
|
|
3669
|
+
if (route.loader.hydrate) {
|
|
3670
|
+
return true;
|
|
3671
|
+
}
|
|
3672
|
+
return (
|
|
3673
|
+
state.loaderData[route.id] === undefined &&
|
|
3674
|
+
// Don't re-run if the loader ran and threw an error
|
|
3675
|
+
(!state.errors || state.errors[route.id] === undefined)
|
|
3676
|
+
);
|
|
3677
|
+
}
|
|
3678
|
+
|
|
3629
3679
|
// Always call the loader on new route instances and pending defer cancellations
|
|
3630
3680
|
if (
|
|
3631
3681
|
isNewLoader(state.loaderData, state.matches[index], match) ||
|
|
@@ -3745,23 +3795,6 @@ function getMatchesToLoad(
|
|
|
3745
3795
|
return [navigationMatches, revalidatingFetchers];
|
|
3746
3796
|
}
|
|
3747
3797
|
|
|
3748
|
-
// Is this route unhydrated (when v7_partialHydration=true) such that we need
|
|
3749
|
-
// to call it's loader on the initial router creation
|
|
3750
|
-
function isUnhydratedRoute(state: RouterState, route: AgnosticDataRouteObject) {
|
|
3751
|
-
if (!route.loader) {
|
|
3752
|
-
return false;
|
|
3753
|
-
}
|
|
3754
|
-
if (route.loader.hydrate) {
|
|
3755
|
-
return true;
|
|
3756
|
-
}
|
|
3757
|
-
return (
|
|
3758
|
-
state.loaderData[route.id] === undefined &&
|
|
3759
|
-
(!state.errors ||
|
|
3760
|
-
// Loader ran but errored - don't re-run
|
|
3761
|
-
state.errors[route.id] === undefined)
|
|
3762
|
-
);
|
|
3763
|
-
}
|
|
3764
|
-
|
|
3765
3798
|
function isNewLoader(
|
|
3766
3799
|
currentLoaderData: RouteData,
|
|
3767
3800
|
currentMatch: AgnosticDataRouteMatch,
|
|
@@ -3897,6 +3930,7 @@ async function callLoaderOrAction(
|
|
|
3897
3930
|
manifest: RouteManifest,
|
|
3898
3931
|
mapRouteProperties: MapRoutePropertiesFunction,
|
|
3899
3932
|
basename: string,
|
|
3933
|
+
v7_relativeSplatPath: boolean,
|
|
3900
3934
|
opts: {
|
|
3901
3935
|
isStaticRequest?: boolean;
|
|
3902
3936
|
isRouteRequest?: boolean;
|
|
@@ -4010,7 +4044,8 @@ async function callLoaderOrAction(
|
|
|
4010
4044
|
matches.slice(0, matches.indexOf(match) + 1),
|
|
4011
4045
|
basename,
|
|
4012
4046
|
true,
|
|
4013
|
-
location
|
|
4047
|
+
location,
|
|
4048
|
+
v7_relativeSplatPath
|
|
4014
4049
|
);
|
|
4015
4050
|
} else if (!opts.isStaticRequest) {
|
|
4016
4051
|
// Strip off the protocol+origin for same-origin + same-basename absolute
|
|
@@ -4057,13 +4092,18 @@ async function callLoaderOrAction(
|
|
|
4057
4092
|
}
|
|
4058
4093
|
|
|
4059
4094
|
let data: any;
|
|
4060
|
-
|
|
4061
|
-
|
|
4062
|
-
|
|
4063
|
-
|
|
4064
|
-
|
|
4065
|
-
|
|
4066
|
-
|
|
4095
|
+
|
|
4096
|
+
try {
|
|
4097
|
+
let contentType = result.headers.get("Content-Type");
|
|
4098
|
+
// Check between word boundaries instead of startsWith() due to the last
|
|
4099
|
+
// paragraph of https://httpwg.org/specs/rfc9110.html#field.content-type
|
|
4100
|
+
if (contentType && /\bapplication\/json\b/.test(contentType)) {
|
|
4101
|
+
data = await result.json();
|
|
4102
|
+
} else {
|
|
4103
|
+
data = await result.text();
|
|
4104
|
+
}
|
|
4105
|
+
} catch (e) {
|
|
4106
|
+
return { type: ResultType.error, error: e };
|
|
4067
4107
|
}
|
|
4068
4108
|
|
|
4069
4109
|
if (resultType === ResultType.error) {
|
package/utils.ts
CHANGED
|
@@ -1149,11 +1149,19 @@ export function getPathContributingMatches<
|
|
|
1149
1149
|
// generate the routePathnames input for resolveTo()
|
|
1150
1150
|
export function getResolveToMatches<
|
|
1151
1151
|
T extends AgnosticRouteMatch = AgnosticRouteMatch
|
|
1152
|
-
>(matches: T[]) {
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1152
|
+
>(matches: T[], v7_relativeSplatPath: boolean) {
|
|
1153
|
+
let pathMatches = getPathContributingMatches(matches);
|
|
1154
|
+
|
|
1155
|
+
// When v7_relativeSplatPath is enabled, use the full pathname for the leaf
|
|
1156
|
+
// match so we include splat values for "." links. See:
|
|
1157
|
+
// https://github.com/remix-run/react-router/issues/11052#issuecomment-1836589329
|
|
1158
|
+
if (v7_relativeSplatPath) {
|
|
1159
|
+
return pathMatches.map((match, idx) =>
|
|
1160
|
+
idx === matches.length - 1 ? match.pathname : match.pathnameBase
|
|
1161
|
+
);
|
|
1162
|
+
}
|
|
1163
|
+
|
|
1164
|
+
return pathMatches.map((match) => match.pathnameBase);
|
|
1157
1165
|
}
|
|
1158
1166
|
|
|
1159
1167
|
/**
|
|
@@ -1201,34 +1209,16 @@ export function resolveTo(
|
|
|
1201
1209
|
// to the current location's pathname and *not* the route pathname.
|
|
1202
1210
|
if (toPathname == null) {
|
|
1203
1211
|
from = locationPathname;
|
|
1204
|
-
} else if (isPathRelative) {
|
|
1205
|
-
let fromSegments = routePathnames[routePathnames.length - 1]
|
|
1206
|
-
.replace(/^\//, "")
|
|
1207
|
-
.split("/");
|
|
1208
|
-
|
|
1209
|
-
if (toPathname.startsWith("..")) {
|
|
1210
|
-
let toSegments = toPathname.split("/");
|
|
1211
|
-
|
|
1212
|
-
// With relative="path", each leading .. segment means "go up one URL segment"
|
|
1213
|
-
while (toSegments[0] === "..") {
|
|
1214
|
-
toSegments.shift();
|
|
1215
|
-
fromSegments.pop();
|
|
1216
|
-
}
|
|
1217
|
-
|
|
1218
|
-
to.pathname = toSegments.join("/");
|
|
1219
|
-
}
|
|
1220
|
-
|
|
1221
|
-
from = "/" + fromSegments.join("/");
|
|
1222
1212
|
} else {
|
|
1223
1213
|
let routePathnameIndex = routePathnames.length - 1;
|
|
1224
1214
|
|
|
1225
|
-
|
|
1215
|
+
// With relative="route" (the default), each leading .. segment means
|
|
1216
|
+
// "go up one route" instead of "go up one URL segment". This is a key
|
|
1217
|
+
// difference from how <a href> works and a major reason we call this a
|
|
1218
|
+
// "to" value instead of a "href".
|
|
1219
|
+
if (!isPathRelative && toPathname.startsWith("..")) {
|
|
1226
1220
|
let toSegments = toPathname.split("/");
|
|
1227
1221
|
|
|
1228
|
-
// With relative="route" (the default), each leading .. segment means
|
|
1229
|
-
// "go up one route" instead of "go up one URL segment". This is a key
|
|
1230
|
-
// difference from how <a href> works and a major reason we call this a
|
|
1231
|
-
// "to" value instead of a "href".
|
|
1232
1222
|
while (toSegments[0] === "..") {
|
|
1233
1223
|
toSegments.shift();
|
|
1234
1224
|
routePathnameIndex -= 1;
|
|
@@ -1237,8 +1227,6 @@ export function resolveTo(
|
|
|
1237
1227
|
to.pathname = toSegments.join("/");
|
|
1238
1228
|
}
|
|
1239
1229
|
|
|
1240
|
-
// If there are more ".." segments than parent routes, resolve relative to
|
|
1241
|
-
// the root / URL.
|
|
1242
1230
|
from = routePathnameIndex >= 0 ? routePathnames[routePathnameIndex] : "/";
|
|
1243
1231
|
}
|
|
1244
1232
|
|