@@ -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 ,
@@ -201,6 +203,10 @@ function createEmptyPart(): KnownRoutePart {
201203// The root of the known route tree.
202204let knownRouteTreeRoot : KnownRoutePart = createEmptyPart ( )
203205
206+ function removeBasePathIfPresent ( pathname : string ) : string {
207+ return hasBasePath ( pathname ) ? removeBasePath ( pathname ) : pathname
208+ }
209+
204210/**
205211 * Learns a route pattern from a server response and inserts it into the cache.
206212 *
@@ -233,7 +239,8 @@ export function discoverKnownRoute(
233239) : FulfilledRouteCacheEntry {
234240 const tree = routeTree
235241
236- const pathnameParts = pathname . split ( '/' ) . filter ( ( p ) => p !== '' )
242+ const routePathname = removeBasePathIfPresent ( pathname )
243+ const pathnameParts = routePathname . split ( '/' ) . filter ( ( p ) => p !== '' )
237244 const firstPart = pathnameParts . length > 0 ? pathnameParts [ 0 ] : null
238245 const remainingParts = pathnameParts . length > 0 ? pathnameParts . slice ( 1 ) : [ ]
239246 let fulfilledEntry : FulfilledRouteCacheEntry
@@ -292,7 +299,9 @@ export function discoverKnownRoute(
292299 )
293300 }
294301
295- persistOfflineNavigationRouteRecord ( now , pathname , nextUrl , fulfilledEntry )
302+ if ( process . env . __NEXT_OFFLINE_NAVIGATIONS ) {
303+ persistOfflineNavigationRouteRecord ( now , pathname , nextUrl , fulfilledEntry )
304+ }
296305 return fulfilledEntry
297306}
298307
@@ -348,6 +357,36 @@ function persistOfflineNavigationRouteRecord(
348357 } )
349358}
350359
360+ export function restoreKnownRouteFromCacheEntry (
361+ now : number ,
362+ pathname : string ,
363+ nextUrl : string | null ,
364+ entry : FulfilledRouteCacheEntry
365+ ) : void {
366+ const routePathname = removeBasePathIfPresent ( pathname )
367+ const pathnameParts = routePathname . split ( '/' ) . filter ( ( p ) => p !== '' )
368+ const firstPart = pathnameParts . length > 0 ? pathnameParts [ 0 ] : null
369+ const remainingParts = pathnameParts . length > 0 ? pathnameParts . slice ( 1 ) : [ ]
370+ const metadataVaryPath = entry . metadata . varyPath as PageVaryPath
371+
372+ discoverKnownRoutePart (
373+ knownRouteTreeRoot ,
374+ entry . tree ,
375+ firstPart ,
376+ remainingParts ,
377+ entry ,
378+ now ,
379+ pathname ,
380+ nextUrl ,
381+ entry . tree ,
382+ metadataVaryPath ,
383+ entry . couldBeIntercepted ,
384+ entry . canonicalUrl ,
385+ entry . supportsPerSegmentPrefetching ,
386+ entry . hasDynamicRewrite
387+ )
388+ }
389+
351390/**
352391 * Gets or creates the dynamic child node for a KnownRoutePart.
353392 * A node can have at most one dynamic child (you can't have both [slug] and
@@ -597,7 +636,8 @@ export function matchKnownRoute(
597636 pathname : string ,
598637 search : NormalizedSearch
599638) : FulfilledRouteCacheEntry | null {
600- const pathnameParts = pathname . split ( '/' ) . filter ( ( p ) => p !== '' )
639+ const routePathname = removeBasePathIfPresent ( pathname )
640+ const pathnameParts = routePathname . split ( '/' ) . filter ( ( p ) => p !== '' )
601641 const resolvedParams : ResolvedParams = new Map ( )
602642 const match = matchKnownRoutePart (
603643 now ,
0 commit comments