Answer the question
In order to leave comments, you need to log in
How to show content on url change in pug, jade?
Hello, when you change the url, you need to show a specific block.
I'm trying to do this:
if window.location.href === "/about"
div
| about
else if window.location.href === "/home"
div
| home
Galp throws an error Cannot read property 'location' of undefined. Please tell me the correct way.
Answer the question
In order to leave comments, you need to log in
pug works statically, i.e. after it is compiled, an html file is created, and this html file is already opened in the browser. If you write like this
if a > 10
div hello
else
div ne hello
When rendering a template, you can add a variable, for example:
if x
div
| about
else if y
div
| home
router.get('/about', (req, res) => {
res.render('ИмяШаблона', {x})
}
I suppose you want to put some emphasis on the menu item if you click on it. You need mixins.
mixin menu(activeItem)
.menu
a.menu-item(href="#" class={"is-active": activeItem === "page-1"})
a.menu-item(href="#" class={"is-active": activeItem === "page-2"})
a.menu-item(href="#" class={"is-active": activeItem === "page-3"})
a.menu-item(href="#" class={"is-active": activeItem === "page-4"})
+menu("page-1")
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question