I'd like to do a simple link in express. I put into the index.jade
a(href='/test', title='View test page') Test
created in /routes a test.js
/*
* GET test page.
*/
exports.test = function(req, res){
res.render('test', { title: 'Genious test' });
};
and a simple test.jade in /views
extends layout
block content
h1= title
p Test page
I added in app.js
app.get('/test', routes.test);
If I click on the link I get the error
Cannot GET /test
Ok. In your app.js add the following lines, and your problems will be solved.
var test = require('./routes/test.js')
app.get('/test', test.test);
This will definitely allow for your app to run and the link to be active.
Instead of creating routes/test.js, add this on to routes/index.js
exports.test = function(req, res){
res.render('test', { title: 'Test' });
};
Then app.get('/test', routes.test); will work as expected.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With