diff --git a/packages/next/client/router.ts b/packages/next/client/router.ts index 32da8433124f4..dcc6f20c7f646 100644 --- a/packages/next/client/router.ts +++ b/packages/next/client/router.ts @@ -45,6 +45,7 @@ const coreMethodFields = [ 'back', 'prefetch', 'beforePopState', + 'addBasePath', ] // Events is a static property on the router, the router doesn't have to be initialized to use it diff --git a/packages/next/next-server/lib/router/router.ts b/packages/next/next-server/lib/router/router.ts index 96cde4b88ea9c..0a86d9e0c063f 100644 --- a/packages/next/next-server/lib/router/router.ts +++ b/packages/next/next-server/lib/router/router.ts @@ -169,6 +169,8 @@ export default class Router implements BaseRouter { } } + addBasePath = addBasePath + onPopState = (e: PopStateEvent): void => { if (!e.state) { // We get state as undefined for two reasons. diff --git a/packages/next/next-server/server/render.tsx b/packages/next/next-server/server/render.tsx index aebb107c555c1..b6d5dfc2929bd 100644 --- a/packages/next/next-server/server/render.tsx +++ b/packages/next/next-server/server/render.tsx @@ -2,7 +2,7 @@ import { IncomingMessage, ServerResponse } from 'http' import { ParsedUrlQuery } from 'querystring' import React from 'react' import { renderToString, renderToStaticMarkup } from 'react-dom/server' -import { NextRouter } from '../lib/router/router' +import { NextRouter, addBasePath } from '../lib/router/router' import mitt, { MittEmitter } from '../lib/mitt' import { loadGetInitialProps, @@ -52,6 +52,7 @@ class ServerRouter implements NextRouter { query: ParsedUrlQuery asPath: string events: any + addBasePath: typeof addBasePath // TODO: Remove in the next major version, as this would mean the user is adding event listeners in server-side `render` method static events: MittEmitter = mitt() @@ -60,6 +61,7 @@ class ServerRouter implements NextRouter { this.pathname = pathname this.query = query this.asPath = as + this.addBasePath = addBasePath } push(): any { noRouter()