diff --git a/lib/router/router.js b/lib/router/router.js index 917202e01d..c0e9ff1d64 100644 --- a/lib/router/router.js +++ b/lib/router/router.js @@ -164,14 +164,14 @@ export default class Router { return true } + const { pathname: asPathname, query: asQuery } = parse(as, true) const { pathname, query } = parse(url, true) // If asked to change the current URL we should reload the current page // (not location.reload() but reload getInitialProps and other Next.js stuffs) // We also need to set the method = replaceState always // as this should not go into the history (That's how browsers work) - // We should compare the new asPath to the current asPath, not the url - if (!this.urlIsNew(as)) { + if (!this.urlIsNew(asPathname, asQuery)) { method = 'replaceState' } @@ -339,10 +339,8 @@ export default class Router { } } - urlIsNew (asPath) { - const { pathname, query } = parse(asPath, true) - const { pathname: curPathname } = parse(this.asPath, true) - return curPathname !== pathname || !shallowEquals(query, this.query) + urlIsNew (pathname, query) { + return this.pathname !== pathname || !shallowEquals(query, this.query) } isShallowRoutingPossible (route) { diff --git a/test/integration/basic/pages/nav/as-path-pushstate.js b/test/integration/basic/pages/nav/as-path-pushstate.js index a85e0ac29a..a5c1482b11 100644 --- a/test/integration/basic/pages/nav/as-path-pushstate.js +++ b/test/integration/basic/pages/nav/as-path-pushstate.js @@ -9,16 +9,7 @@ export default withRouter(({router: {asPath, query}}) => { hello -