From 7c64336e9d44770ab7fcc0b54643e216bd871bfe Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Sun, 10 Feb 2019 05:36:32 +0100 Subject: [PATCH] Revert "should not change method to replaceState unless asPath is the same (#6033)" This reverts commit ab46c45146ca8a1677d9ecacc21522fc60a17397. --- lib/router/router.js | 10 ++++------ test/integration/basic/pages/nav/as-path-pushstate.js | 11 +---------- test/integration/basic/test/client-navigation.js | 5 ----- 3 files changed, 5 insertions(+), 21 deletions(-) diff --git a/lib/router/router.js b/lib/router/router.js index 917202e0..c0e9ff1d 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 a85e0ac2..a5c1482b 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 -
- - else - -
-
- - normal hello - -
+ {query.something === 'hello' && same query } diff --git a/test/integration/basic/test/client-navigation.js b/test/integration/basic/test/client-navigation.js index 143d49fd..fcdbfa6a 100644 --- a/test/integration/basic/test/client-navigation.js +++ b/test/integration/basic/test/client-navigation.js @@ -648,11 +648,6 @@ export default (context, render) => { await browser.back().waitForElementByCss('#something-hello') const queryThree = JSON.parse(await browser.elementByCss('#router-query').text()) expect(queryThree.something).toBe('hello') - await browser.elementByCss('#else').click().waitForElementByCss('#something-else') - await browser.elementByCss('#hello2').click().waitForElementByCss('#nav-as-path-pushstate') - await browser.back().waitForElementByCss('#something-else') - const queryFour = JSON.parse(await browser.elementByCss('#router-query').text()) - expect(queryFour.something).toBe(undefined) } finally { if (browser) { browser.close()