Good morning all. I am trying to pass data to a view which is loaded in express via a redirect:
res.redirect('/manage-account/2-0/returns/answers')
The above is an html view which loads fine with just the redirect, but I want to pass some data. I can't pass data as part of a redirect, as far as I understand only a redirect?
So I have set up a GET
for that route, and am trying to render the view with the data, but I am getting the error:
template not found: /manage-account/2-0/returns/answers.html
This is the route I created and how the page is initially redirected to in another view:
router.get('/manage-account/2-0/returns/questions', function (req, res) {
// stuff
res.redirect('/manage-account/2-0/returns/answers')
})
router.get('/manage-account/2-0/returns/answers', function (req, res) {
res.render('/manage-account/2-0/returns/answers', { data })
})
I found the possible way to write.
Server Side app.engine('html', require('ejs').renderFile);
-
app.get('/main', function(req, res) {
var name = 'hello';
res.render(__dirname + "/views/layouts/main.html", {name:name});
});
Client side (main.html) -
<h1><%= name %></h1>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.