ActiveRouteLoader navigating to top on page load

Hey everybody,

I’m pretty new to RedwoodJS so there’s a good chance that I’m missing something basic here. I’ve noticed that when I navigate from page A (which has a lot of content that requires scrolling) to page B, then hit the back button to return to page A, ActiveRouteLoader auto-scrolls me up to the top of the page.

Here’s line 73 of node_modules/@redwoodjs/router/dist/active-route-loader.js:

(_global = global) === null || _global === void 0 ? void 0 : _global.scrollTo(0, 0);

In fact, even if I explicitly scroll to some point in the page, for example by calling:

React.useEffect(() => {
  window.scrollTo({ top: searchScroll })
})

I find that ActiveRouteLoader will actually scroll to the top of the page even after the page is loaded. I found a hacky way to get around this by putting my scrollTo function in a timeout:

  React.useEffect(() => {
    setTimeout(() => {
      window.scrollTo({ top: searchScroll })
    }, 0)
  })

but I would really prefer to find the “Redwood way” to scroll to the right position on the screen. I’m happy to provide any context needed.

Hi @dcorbitt this scrollTo behavior stems from an issue from way back in October 2020:

And that will give some context for why it behaves that way.

Maybe this behavior should be configured on a page or route perhaps?