I’m trying to add a class ‘dark’ if it is in localstorage, and remove it if there is ‘light’ as ‘mode’ in localstorage.
However, I have the feeling that all pages of my blazor .NET8 application are cached. It saves the mode in local storage, but when I switch pages it doesn’t execute the javascript ‘onload’ statement. Only if I then manually refresh the page again.
I’m curious, does Blazor cache all the pages, because it doesn’t re-render the page when you go to it. Does this have to do with a specific rendermode in Blazor?
What I’ve tried is using the ‘onload’ param in the body tag. However the onload statement is’nt executed when rendering the page.
<body onload="localStorage.getItem('mode') === 'dark' ? document.querySelector('body').classList.add('dark') : document.querySelector('body').classList.remove('dark')">
Franck is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.