diff --git a/packages/next/next-server/lib/router/router.ts b/packages/next/next-server/lib/router/router.ts index 28de2e6628014..54397b7475b81 100644 --- a/packages/next/next-server/lib/router/router.ts +++ b/packages/next/next-server/lib/router/router.ts @@ -650,11 +650,14 @@ export default class Router implements BaseRouter { if (as.substr(0, 2) !== '//') { // in order for `e.state` to work on the `onpopstate` event // we have to register the initial route upon initialization + const options: TransitionOptions = { locale } + ;(options as any)._shouldResolveHref = as !== pathname + this.changeState( 'replaceState', formatWithValidation({ pathname: addBasePath(pathname), query }), getURL(), - { locale } + options ) } diff --git a/test/integration/build-output/test/index.test.js b/test/integration/build-output/test/index.test.js index aa10ed22ba789..ad72cba91446b 100644 --- a/test/integration/build-output/test/index.test.js +++ b/test/integration/build-output/test/index.test.js @@ -149,7 +149,7 @@ describe('Build Output', () => { true ) - expect(parseFloat(mainSize)).toBeCloseTo(gz ? 19.4 : 60.5, 1) + expect(parseFloat(mainSize)).toBeCloseTo(gz ? 19.4 : 60.6, 1) expect(mainSize.endsWith('kB')).toBe(true) expect(parseFloat(frameworkSize)).toBeCloseTo(gz ? 42.0 : 130, 1) diff --git a/test/integration/rewrite-with-browser-history/next.config.js b/test/integration/rewrite-with-browser-history/next.config.js new file mode 100644 index 0000000000000..0cfae327c92fa --- /dev/null +++ b/test/integration/rewrite-with-browser-history/next.config.js @@ -0,0 +1,10 @@ +module.exports = { + rewrites() { + return [ + { + source: '/:pagePrefix/:path*', + destination: '/dynamic-page/:pagePrefix/:path*', + }, + ] + }, +} diff --git a/test/integration/rewrite-with-browser-history/pages/dynamic-page/[[...param]].js b/test/integration/rewrite-with-browser-history/pages/dynamic-page/[[...param]].js new file mode 100644 index 0000000000000..47e56e79e024f --- /dev/null +++ b/test/integration/rewrite-with-browser-history/pages/dynamic-page/[[...param]].js @@ -0,0 +1,23 @@ +import { useRouter } from 'next/router' +import Link from 'next/link' + +export default function Page(props) { + const router = useRouter() + + return ( + <> +
another page
+{router.pathname}
+{JSON.stringify(router.query)}
+ + + Go back to index + +index page
+{router.pathname}
+{JSON.stringify(router.query)}
+ +