Reputation: 23
I started working with node.js
and express
. Now I want to add a link which refers to another jade file (Open a new site).
My folder structure is the following:
test/app.js
test/views/index.jade
test/views/games.jade
My target is to refer with a link inside the index.jade to the games.jade. The index works perfect but if I try to refer to games.jade, I get the following error:
Cannot GET /games.jade
Here's a little part of my app.js
app.get('/', function (req, res){
res.render('index');
});
app.get('/', function(req, res){
res.render('games.jade');
});
Inside the index.jade, I try to refer with the following line:
a(href="games.jade") Games
So how do I fix this issue? I think there is a routing problem but I can't find the solution. I also checked this question but there wasn't any success: Linking to other jade files
Upvotes: 2
Views: 698
Reputation: 66
You will first need to register that route with your apps router for the route /games
Then use the route like so.
app.get('/', function (req, res){
res.render('index');
});
app.get('/games', function(req, res){
res.render('games.jade');
});
the route or link will then be (href="/games") Games
Upvotes: 1
Reputation: 14590
That's wrong you can't have two equal routes app.get('/')
do a new one like:
app.get('/games', function(req, res){
res.render('games.jade');
});
And then link that like this:
a(href="/games") Games
Upvotes: 1