Just starting out with Blazor. I've been working on a Blazor project that utilizes DevExpress components, causing some issues with scrolling. My goal is to have the page start at the top every time I navigate to a new page. Currently, I've found a temporary solution by using the OnAfterRenderAsync method in the Main Navigation Layout to trigger this functionality.
protected override async Task OnAfterRenderAsync(bool firstRender)
{
await JsRuntime.InvokeVoidAsync("ScrollTop");
}
This method is implemented in the MainLayout component and the corresponding code can be found in a separate JS file:
function ScrollTop() {
document.getElementsByClassName('content')[0].scrollTop = 0;
}
Although this approach somewhat works by loading pages at the top, any changes made to in-page components cause the page to scroll back up. Is there a way to modify this so that the event only fires when the page location is changed?