Commit 7c64336e authored by Tim Neutkens's avatar Tim Neutkens

Revert "should not change method to replaceState unless asPath is the same (#6033)"

This reverts commit ab46c451.
parent 155423f2
...@@ -164,14 +164,14 @@ export default class Router { ...@@ -164,14 +164,14 @@ export default class Router {
return true return true
} }
const { pathname: asPathname, query: asQuery } = parse(as, true)
const { pathname, query } = parse(url, true) const { pathname, query } = parse(url, true)
// If asked to change the current URL we should reload the current page // If asked to change the current URL we should reload the current page
// (not location.reload() but reload getInitialProps and other Next.js stuffs) // (not location.reload() but reload getInitialProps and other Next.js stuffs)
// We also need to set the method = replaceState always // We also need to set the method = replaceState always
// as this should not go into the history (That's how browsers work) // 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(asPathname, asQuery)) {
if (!this.urlIsNew(as)) {
method = 'replaceState' method = 'replaceState'
} }
...@@ -339,10 +339,8 @@ export default class Router { ...@@ -339,10 +339,8 @@ export default class Router {
} }
} }
urlIsNew (asPath) { urlIsNew (pathname, query) {
const { pathname, query } = parse(asPath, true) return this.pathname !== pathname || !shallowEquals(query, this.query)
const { pathname: curPathname } = parse(this.asPath, true)
return curPathname !== pathname || !shallowEquals(query, this.query)
} }
isShallowRoutingPossible (route) { isShallowRoutingPossible (route) {
......
...@@ -9,16 +9,7 @@ export default withRouter(({router: {asPath, query}}) => { ...@@ -9,16 +9,7 @@ export default withRouter(({router: {asPath, query}}) => {
<a id='hello'>hello</a> <a id='hello'>hello</a>
</Link> </Link>
</div> </div>
<div>
<Link href='/nav/as-path-pushstate' as='/something/else'>
<a id='else'>else</a>
</Link>
</div>
<div>
<Link href='/nav/as-path-pushstate' as='/nav/as-path-pushstate'>
<a id='hello2'>normal hello</a>
</Link>
</div>
{query.something === 'hello' && <Link href='/nav/as-path-pushstate?something=hello' as='/something/same-query'> {query.something === 'hello' && <Link href='/nav/as-path-pushstate?something=hello' as='/something/same-query'>
<a id='same-query'>same query</a> <a id='same-query'>same query</a>
</Link>} </Link>}
......
...@@ -648,11 +648,6 @@ export default (context, render) => { ...@@ -648,11 +648,6 @@ export default (context, render) => {
await browser.back().waitForElementByCss('#something-hello') await browser.back().waitForElementByCss('#something-hello')
const queryThree = JSON.parse(await browser.elementByCss('#router-query').text()) const queryThree = JSON.parse(await browser.elementByCss('#router-query').text())
expect(queryThree.something).toBe('hello') 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 { } finally {
if (browser) { if (browser) {
browser.close() browser.close()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment