UI breaking after page refresh in Blazor

Viewed 31

Below is the code snippet. Page works fine first time when loaded. And if I navigate to another page and come back to the same page, the Jscript file doesn't work. How to fix this?

 private IJSObjectReference? module;

 protected override async Task OnAfterRenderAsync(bool firstRender)
 {
    if (firstRender)
    {
        module = await jsRuntime.InvokeAsync<IJSObjectReference>("import", "/app-assets/js/scripts/page.js");
    }
 }
0 Answers
Related