@@ -54,6 +54,8 @@ import {
5454 createMetadataRouteTree ,
5555} from './cache'
5656import { isValueExpired } from './cache-map'
57+ import { hasBasePath } from '../../has-base-path'
58+ import { removeBasePath } from '../../remove-base-path'
5759import { doesStaticSegmentAppearInURL } from '../../route-params'
5860import type {
5961 NormalizedNextUrl ,
@@ -186,6 +188,10 @@ function createEmptyPart(): KnownRoutePart {
186188// The root of the known route tree.
187189let knownRouteTreeRoot : KnownRoutePart = createEmptyPart ( )
188190
191+ function removeBasePathIfPresent ( pathname : string ) : string {
192+ return hasBasePath ( pathname ) ? removeBasePath ( pathname ) : pathname
193+ }
194+
189195/**
190196 * Learns a route pattern from a server response and inserts it into the cache.
191197 *
@@ -218,7 +224,8 @@ export function discoverKnownRoute(
218224) : FulfilledRouteCacheEntry {
219225 const tree = routeTree
220226
221- const pathnameParts = pathname . split ( '/' ) . filter ( ( p ) => p !== '' )
227+ const routePathname = removeBasePathIfPresent ( pathname )
228+ const pathnameParts = routePathname . split ( '/' ) . filter ( ( p ) => p !== '' )
222229 const firstPart = pathnameParts . length > 0 ? pathnameParts [ 0 ] : null
223230 const remainingParts = pathnameParts . length > 0 ? pathnameParts . slice ( 1 ) : [ ]
224231 let fulfilledEntry : FulfilledRouteCacheEntry
@@ -325,6 +332,36 @@ function persistOfflineNavigationRouteRecord(
325332 } )
326333}
327334
335+ export function restoreKnownRouteFromCacheEntry (
336+ now : number ,
337+ pathname : string ,
338+ nextUrl : string | null ,
339+ entry : FulfilledRouteCacheEntry
340+ ) : void {
341+ const routePathname = removeBasePathIfPresent ( pathname )
342+ const pathnameParts = routePathname . split ( '/' ) . filter ( ( p ) => p !== '' )
343+ const firstPart = pathnameParts . length > 0 ? pathnameParts [ 0 ] : null
344+ const remainingParts = pathnameParts . length > 0 ? pathnameParts . slice ( 1 ) : [ ]
345+ const metadataVaryPath = entry . metadata . varyPath as PageVaryPath
346+
347+ discoverKnownRoutePart (
348+ knownRouteTreeRoot ,
349+ entry . tree ,
350+ firstPart ,
351+ remainingParts ,
352+ entry ,
353+ now ,
354+ pathname ,
355+ nextUrl ,
356+ entry . tree ,
357+ metadataVaryPath ,
358+ entry . couldBeIntercepted ,
359+ entry . canonicalUrl ,
360+ entry . supportsPerSegmentPrefetching ,
361+ entry . hasDynamicRewrite
362+ )
363+ }
364+
328365/**
329366 * Gets or creates the dynamic child node for a KnownRoutePart.
330367 * A node can have at most one dynamic child (you can't have both [slug] and
@@ -574,7 +611,8 @@ export function matchKnownRoute(
574611 pathname : string ,
575612 search : NormalizedSearch
576613) : FulfilledRouteCacheEntry | null {
577- const pathnameParts = pathname . split ( '/' ) . filter ( ( p ) => p !== '' )
614+ const routePathname = removeBasePathIfPresent ( pathname )
615+ const pathnameParts = routePathname . split ( '/' ) . filter ( ( p ) => p !== '' )
578616 const resolvedParams : ResolvedParams = new Map ( )
579617 const match = matchKnownRoutePart (
580618 now ,
0 commit comments