diff --git a/packages/next/client/index.js b/packages/next/client/index.js index fc7d439a8a5f4..4292764b202ec 100644 --- a/packages/next/client/index.js +++ b/packages/next/client/index.js @@ -9,7 +9,7 @@ import { RouterContext } from '../next-server/lib/router-context' import { isDynamicRoute } from '../next-server/lib/router/utils/is-dynamic' import * as envConfig from '../next-server/lib/runtime-config' import { getURL, loadGetInitialProps, ST } from '../next-server/lib/utils' -import { delBasePath } from '../next-server/lib/router/router' +import { delBasePath, basePath } from '../next-server/lib/router/router' import initHeadManager from './head-manager' import PageLoader from './page-loader' import measureWebVitals from './performance-relayer' @@ -52,15 +52,7 @@ envConfig.setConfig({ let asPath = getURL() // make sure not to attempt stripping basePath for 404s -if ( - page !== '/404' && - !( - page === '/_error' && - hydrateProps && - hydrateProps.pageProps && - hydrateProps.pageProps.statusCode === 404 - ) -) { +if (asPath.startsWith(basePath)) { asPath = delBasePath(asPath) } diff --git a/packages/next/next-server/lib/router/router.ts b/packages/next/next-server/lib/router/router.ts index a55631b2100cf..538db7544ff6b 100644 --- a/packages/next/next-server/lib/router/router.ts +++ b/packages/next/next-server/lib/router/router.ts @@ -22,7 +22,7 @@ import { normalizePathTrailingSlash, } from '../../../client/normalize-trailing-slash' -const basePath = (process.env.__NEXT_ROUTER_BASEPATH as string) || '' +export const basePath = (process.env.__NEXT_ROUTER_BASEPATH as string) || '' function buildCancellationError() { return Object.assign(new Error('Route Cancelled'), {