Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,14 @@ class ScrollContext extends React.Component {

// The "scroll-behavior" package expects the "action" to be on the location
// object so let's copy it over.
if (!location.action) {
location.action = `push`

// Temp hack while awaiting https://github.com/reach/router/issues/119
if (window.__navigatingToLink) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure this will work everywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for suspecting it wouldn't?

location.action = `PUSH`
} else {
location.action = `POP`
}

this.scrollBehavior.updateScroll(prevRouterProps, { history, location })
}

Expand Down
12 changes: 11 additions & 1 deletion packages/gatsby/cache-dir/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,17 @@ const onPreRouteUpdate = location => {
const onRouteUpdate = location => {
if (!maybeRedirect(location.pathname)) {
apiRunner(`onRouteUpdate`, { location })
// Temp hack while awaiting https://github.com/reach/router/issues/119
window.__navigatingToLink = false
}
}

const navigate = (to, options) => {
const navigate = (to, options = {}) => {
// Temp hack while awaiting https://github.com/reach/router/issues/119
if (!options.replace) {
window.__navigatingToLink = true
}

let { pathname } = parsePath(to)
const redirect = redirectMap[pathname]

Expand Down Expand Up @@ -109,6 +116,9 @@ function shouldUpdateScroll(prevRouterProps, { location: { pathname } }) {
}

function init() {
// Temp hack while awaiting https://github.com/reach/router/issues/119
window.__navigatingToLink = false

setApiRunnerForLoader(apiRunner)
window.___loader = loader
window.___push = to => navigate(to, { replace: false })
Expand Down