1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

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

This reverts commit ab46c45146.
This commit is contained in:
Tim Neutkens 2019-02-10 05:36:32 +01:00
parent 155423f26b
commit 7c64336e9d
3 changed files with 5 additions and 21 deletions

View file

@ -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) {

View file

@ -9,16 +9,7 @@ export default withRouter(({router: {asPath, query}}) => {
<a id='hello'>hello</a>
</Link>
</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'>
<a id='same-query'>same query</a>
</Link>}

View file

@ -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()