diff --git a/packages/next-server/lib/router/router.ts b/packages/next-server/lib/router/router.ts
index 25a600110d5586316577ed589f51d05a6e60323b..dc14affa8eed1f297228a1c22c9fc01aa5a3a011 100644
--- a/packages/next-server/lib/router/router.ts
+++ b/packages/next-server/lib/router/router.ts
@@ -275,8 +275,9 @@ export default class Router implements BaseRouter {
// detect dynamic routing
if (route.indexOf('/$') !== -1) {
+ const { pathname: asPathname } = parse(as)
const rr = getRouteRegex(route)
- const routeMatch = getRouteMatcher(rr)(as)
+ const routeMatch = getRouteMatcher(rr)(asPathname)
if (!routeMatch) {
console.error(
"Your ``'s `as` value is incompatible with the `href` value. This is invalid."
diff --git a/test/integration/dynamic-routing/pages/index.js b/test/integration/dynamic-routing/pages/index.js
index 2b0b2f0b52104b783edd0f86afbb57cc05c6a8f4..37b391a3c0ca2f051cc5dfcf2d41feb2b3d786a2 100644
--- a/test/integration/dynamic-routing/pages/index.js
+++ b/test/integration/dynamic-routing/pages/index.js
@@ -22,6 +22,10 @@ const Page = () => (
View comment 123 on blog post 321
+
+
+ View post 1 with query
+
)
diff --git a/test/integration/dynamic-routing/test/index.test.js b/test/integration/dynamic-routing/test/index.test.js
index 650c7edb5b0957eaba61e77d22d0954eb39b3861..e56cd5caf7f5c5e058993f729c81a21637ebfb8c 100644
--- a/test/integration/dynamic-routing/test/index.test.js
+++ b/test/integration/dynamic-routing/test/index.test.js
@@ -58,6 +58,14 @@ function runTests () {
expect(html).toMatch(/blog post.*321.*comment.*123/i)
})
+ it('should render dynamic route with query', async () => {
+ const browser = await webdriver(appPort, '/')
+ await browser.elementByCss('#view-post-1-with-query').click()
+ await waitFor(1000)
+ const url = await browser.eval('window.location.search')
+ expect(url).toBe('?fromHome=true')
+ })
+
it('should navigate to a dynamic page successfully', async () => {
let browser
try {