Skip to content

Commit

Permalink
Revert "should not change method to replaceState unless asPath is the…
Browse files Browse the repository at this point in the history
… same (#6033)"

This reverts commit ab46c45.
  • Loading branch information
timneutkens committed Feb 10, 2019
1 parent 155423f commit 7c64336
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 21 deletions.
10 changes: 4 additions & 6 deletions lib/router/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}

Expand Down Expand Up @@ -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) {
Expand Down
11 changes: 1 addition & 10 deletions test/integration/basic/pages/nav/as-path-pushstate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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>}
Expand Down
5 changes: 0 additions & 5 deletions test/integration/basic/test/client-navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 7c64336

Please sign in to comment.