diff --git a/packages/next/client/index.js b/packages/next/client/index.js index 39a2e781d529d61824283515ac11e24a568cde26..b0d0cef9ebe8cf7eff7eded2cfec1b2db554c42c 100644 --- a/packages/next/client/index.js +++ b/packages/next/client/index.js @@ -101,8 +101,9 @@ class Container extends React.Component { // If page was exported and has a querystring // If it's a dynamic route or has a querystring if ( - data.nextExport && - (isDynamicRoute(router.pathname) || location.search) + (data.nextExport && + (isDynamicRoute(router.pathname) || location.search)) || + (Component.__NEXT_SPR && location.search) ) { // update query on mount for exported pages router.replace( diff --git a/test/integration/prerender/pages/blog/[post]/index.js b/test/integration/prerender/pages/blog/[post]/index.js index 5449c6d7bb8caaca0fcfd43bf89435eaee9a54ca..135d01cfeb483fe24c6c8c508a42c456675b52b4 100644 --- a/test/integration/prerender/pages/blog/[post]/index.js +++ b/test/integration/prerender/pages/blog/[post]/index.js @@ -1,5 +1,6 @@ import React from 'react' import Link from 'next/link' +import { useRouter } from 'next/router' // eslint-disable-next-line camelcase export async function unstable_getStaticPaths() { @@ -37,6 +38,7 @@ export default ({ post, time }) => { <>

Post: {post}

time: {time} +
{JSON.stringify(useRouter().query)}
to home diff --git a/test/integration/prerender/test/index.test.js b/test/integration/prerender/test/index.test.js index f63e27826fc3c9bb019d2ecadc42d6042330c78a..7e2ac90f726f883736e520dd7d6c171bdbd01885 100644 --- a/test/integration/prerender/test/index.test.js +++ b/test/integration/prerender/test/index.test.js @@ -213,6 +213,14 @@ const runTests = (dev = false) => { expect(text).toMatch(/a normal page/) }) + it('should parse query values on mount correctly', async () => { + const browser = await webdriver(appPort, '/blog/post-1?another=value') + await waitFor(2000) + const text = await browser.elementByCss('#query').text() + expect(text).toMatch(/another.*?value/) + expect(text).toMatch(/post.*?post-1/) + }) + if (dev) { it('should always call getStaticProps without caching in dev', async () => { const initialRes = await fetchViaHTTP(appPort, '/something')