S
SolidJS7mo ago
Mercy

Modifying <body> tag

I am trying to figure out how to modify the body tag to remove a certain class for certain pages to no avail. The class needs to be removed from the body for pages that do not have a sidebar.
function NavbarSpacer() {
const removeClass = () => {
/// check if body has the class
let hasClass = document.body.classList.contains("ps-lg-sbwidth");

// get current url
const url = window.location.pathname;
if (url === "/login" || url === "/registration") {
if (hasClass) {
document.body.classList.remove("ps-lg-sbwidth");
}
} else if (!hasClass) {
document.body.classList.add("ps-lg-sbwidth");
}
};

removeClass();

return (
<>
</>
);
}

export default NavbarSpacer;
function NavbarSpacer() {
const removeClass = () => {
/// check if body has the class
let hasClass = document.body.classList.contains("ps-lg-sbwidth");

// get current url
const url = window.location.pathname;
if (url === "/login" || url === "/registration") {
if (hasClass) {
document.body.classList.remove("ps-lg-sbwidth");
}
} else if (!hasClass) {
document.body.classList.add("ps-lg-sbwidth");
}
};

removeClass();

return (
<>
</>
);
}

export default NavbarSpacer;
this only works when i load a page for the first time or refresh
1 Reply
REEEEE
REEEEE7mo ago
Use createEffect and useLocation if you have solid-router installed
Want results from more Discord servers?
Add your server