【发布时间】:2021-11-11 13:17:12
【问题描述】:
我想创建一个 node.js 应用程序,我想在其中以特定顺序呈现多个不同的哈巴狗模板。例如。用户单击“template1”上的按钮后,应呈现“template2”。如果用户按下“template2”上的按钮,则应该呈现“template3”...
此时,我有一个简单的 app.post 调用(见下文)在单击“template1”按钮后呈现“template2”。
如何在“template2”之后渲染“template3”?我是否必须包含某种 if 块来检查用户当前使用的模板?
app.post('/', async function(req, res, next) {
res.render('template2')
});
【问题讨论】:
-
每个模板都可以有自己的路径,例如,
app.post('/template2', async function(req, res, next) {res.render('template2')})。 -
只需为每个模板创建一个路由,或使用参数,即
/template/:id,但这将涉及您验证 req.params.id 是在您的视图目录中找到的模板,这可能超出您的理解