Relative links in Express/Jade
express, pug
Solution
As you already noticed yourself, when you open `/cats` it's to be expected that a relative link to `fluffy` would lead you to `/fluffy` :)
Bit of background: the default behavior of Express is to treat `/cats` and `/cats/` as the same, and both will trigger the same route.
You either have to take that into account when you create links (especially relative links), or tell Express to treat them as two separate routes:
app.enable('strict routing');
app.get('/cats/', function(req, res) {
...
});
This will match `/cats/`, but not `/cats`. Of course, when you leave off the trailing slash in the route definition, this behavior will be reversed.
Problem
I'm trying to get my Jade template to write a hyperlink (`<a>`) relative to the current URL. For example, my view is called from `http://localhost/cats` and it looks like this: ``` extends layout block content a(href='fluffy') Fluffy ``` When the link is clicked, it takes me to `http://localhost/fluffy`, instead of `http://localhost/cats/fluffy` Things I've tried: - `a(href='./fluffly')` - `a(href='\\fluffy')` - `a(href='/fluffy')` Just about the only thing that works is writing out the absolute path, like `a(href='cats/fluffy')`. Surely there's a better way to do it.