C
C#14mo ago
skyslide22

✅ How to register a onNavigate/navigation event callback in Net8 SSR?

blazor.web.js replaced the entire html on navigate with the response, but scripts like <script src="js/myscript.js></script> are NOT executed again. so if any js is used it will break on any navigation change. how can i register a callback for a navigation change? i have seen there is Window.Blazor.addEventListener() but there is absolute no documentation
1 Reply
skyslide22
skyslide22OP14mo ago
fixed:
window.Blazor.addEventListener("enhancedload", initMyStuff)

initMyStuff();

function initMyStuff() {
const blabla = document.querySelectorAll(".mythings");
// do what you want ...
}
window.Blazor.addEventListener("enhancedload", initMyStuff)

initMyStuff();

function initMyStuff() {
const blabla = document.querySelectorAll(".mythings");
// do what you want ...
}
Want results from more Discord servers?
Add your server