When rendering a view in expressjs, all you need to do is specify an endpoint and call that specific endpoint.
It's important not to directly call the location of the .ejs
file.
For instance, in the following code snippet, login.ejs
will be rendered automatically behind the scenes when res.render('login')
is called:
router.get('/home', function(req, res, next) {
res.render('login');
});
Your hyperlink should only call the endpoint mapped by the router:
<a href="/home"><li> LOGIN </li></a>
If you are working on UI design using EJS and only responsible for the front-end part, you can create dummy data to render an EJS page without running the entire website with a database.
For example, assuming there is dummy data available for rendering an EJS page, you can achieve this by obtaining the data from the developer and writing code like the following:
router.get('/home', function(req, res, next) {
var data = {"name": "Emmanuel"}
res.render('login', data);
});
In this code snippet, the data is hardcoded as temporary
.