Reputation: 667
I am creating a sample blog website in which homepage contains blogs in order of the day it is posted. The layout of the blog is like below :
Day 1
some paragraph text.....Read More
Day 2
some paragraph text.....Read More
Now how do route/redirect the page to particular post page using Day as Id and using anchor tag when clicking Read More
Upvotes: 0
Views: 1121
Reputation: 239
EJS Code:
...
<!--
day=[
{
id:1,
...any_other_data
},
{
id:2,
...any_other_data
}
]
-->
<% for (var i = 0; i < day.length; i++) { %>
<a href="<%= 'example/'+day[i].id %>">Read More</a>
<a href="<%= 'https:www.example.com/example/'+day[i].id %>">Read More</a>
<%}%>
...
I hope this should work! In the above code the dynamic url will work for both the codes
Dynamic Routing with Express.js
app.get('example/:id', function(req , res){
res.render('Day' + req.params.id);
});
Upvotes: 1