A JavaScript function has been implemented to create a theme changer toggle switch, which switches between two different .css files - one for dark theme and the other for white theme. The theme switcher successfully works on base routes like "./routes", however, it is not functioning properly on routes such as "./routes/{id}".
var checkbox = document.getElementById("theme-changer-checkbox");
var body = document.getElementById("kt_body");
var el = document.getElementById("theme-change-styleSheet");
checkbox.onclick = function() {
myFunction();
};
function myFunction() {
if (checkbox.checked) {
el.href = "css/dashboardDarkTheme.css";
body.style.setProperty("background", "#152036", "important");
} else {
el.href = "css/dashboardWhiteTheme.css";
body.style.setProperty("background", "white", "important");
}
}
An attempt was made to add the URL before href routes in the following manner:
<link id="theme-change-styleSheet" rel="stylesheet" href="{{URL('css/dashboardWhiteTheme.css')}}"></link>