diff --git a/packages/next/src/build/index.ts b/packages/next/src/build/index.ts index 29c653a7eb969..2b02c651ad160 100644 --- a/packages/next/src/build/index.ts +++ b/packages/next/src/build/index.ts @@ -1020,7 +1020,9 @@ export default async function build( const appPaths = Array.from(appPageKeys) // Interception routes are modelled as beforeFiles rewrites - rewrites.beforeFiles.push(...generateInterceptionRoutesRewrites(appPaths)) + rewrites.beforeFiles.push( + ...generateInterceptionRoutesRewrites(appPaths, config.basePath) + ) const totalAppPagesCount = appPaths.length diff --git a/packages/next/src/lib/generate-interception-routes-rewrites.ts b/packages/next/src/lib/generate-interception-routes-rewrites.ts index 85fed64167498..931f2199675c2 100644 --- a/packages/next/src/lib/generate-interception-routes-rewrites.ts +++ b/packages/next/src/lib/generate-interception-routes-rewrites.ts @@ -44,7 +44,8 @@ function voidParamsBeforeInterceptionMarker(path: string): string { } export function generateInterceptionRoutesRewrites( - appPaths: string[] + appPaths: string[], + basePath = '' ): Rewrite[] { const rewrites: Rewrite[] = [] @@ -70,8 +71,8 @@ export function generateInterceptionRoutesRewrites( .slice(2, -3) rewrites.push({ - source: normalizedInterceptedRoute, - destination: normalizedAppPath, + source: `${basePath}${normalizedInterceptedRoute}`, + destination: `${basePath}${normalizedAppPath}`, has: [ { type: 'header', diff --git a/packages/next/src/server/lib/router-utils/setup-dev-bundler.ts b/packages/next/src/server/lib/router-utils/setup-dev-bundler.ts index 130d54fedc6a3..4bb7c443fa202 100644 --- a/packages/next/src/server/lib/router-utils/setup-dev-bundler.ts +++ b/packages/next/src/server/lib/router-utils/setup-dev-bundler.ts @@ -2270,13 +2270,15 @@ async function startWatcher(opts: SetupOpts) { : undefined opts.fsChecker.interceptionRoutes = - generateInterceptionRoutesRewrites(Object.keys(appPaths))?.map((item) => - buildCustomRoute( - 'before_files_rewrite', - item, - opts.nextConfig.basePath, - opts.nextConfig.experimental.caseSensitiveRoutes - ) + generateInterceptionRoutesRewrites(Object.keys(appPaths))?.map( + (item) => + buildCustomRoute( + 'before_files_rewrite', + item, + opts.nextConfig.basePath, + opts.nextConfig.experimental.caseSensitiveRoutes + ), + opts.nextConfig.basePath ) || [] const exportPathMap =