Skip to content

Commit

Permalink
Fixed link hash behavior across pages (vercel#5161)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljonathanblack committed Oct 30, 2018
1 parent 344ca37 commit 441727d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 3 additions & 1 deletion packages/next-server/lib/router/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,11 @@ export default class Router {
}

Router.events.emit('beforeHistoryChange', as)

this.changeState(method, url, as, options)
const hash = window.location.hash.substring(1)
this.scrollToHash(as)

const hash = window.location.hash.substring(1)
this.set(route, pathname, query, as, { ...routeInfo, hash })

if (error) {
Expand Down
3 changes: 1 addition & 2 deletions test/unit/router.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ describe('Router', () => {
await router.change('pushState', '/', '/test#test', {})
const result = await router.change('pushState', '/', '/', {})
expect(result).toBeTruthy()
// @todo scrollToHash should be called for all hash requests
// expect(router.scrollToHash).toHaveBeenCalledWith('/test#test')
expect(router.scrollToHash).toHaveBeenCalledWith('/test#test')
expect(router.fetchComponent).toHaveBeenCalled()
expect(Router.events.emit).toHaveBeenCalledWith('routeChangeStart', '/test#test')
expect(Router.events.emit).toHaveBeenCalledWith('routeChangeComplete', '/test#test')
Expand Down

0 comments on commit 441727d

Please sign in to comment.