javascript - 使用 Express 4 更改渲染 View 的 url

标签 javascript node.js express

我有一个帖子请求,问题是当我呈现我的 View 时,它呈现到 /link/123 而我希望该 View 呈现到 /anotherlink 我本可以使用 res.redirect ('/anotherlink') 但我需要呈现不同的数据

 app.post('/link/:id',function (req, res, next){
   res.render('products', {
   data : 'help please'
   });
});

最佳答案

我找到了一个更好的解决方案,即在不重新加载的情况下更改 View 中的 url:window.history.pushState("", "", '/wantedLink');

关于javascript - 使用 Express 4 更改渲染 View 的 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39308798/

相关文章:

javascript - React hooks,每个状态值一个钩子(Hook)?

javascript - Internet Explorer 父窗口上的动态 CSS

javascript - 'var' 为 null 或不是对象

javascript - "Vertically stick on the middle screen"错误

javascript - 将 JSON 对象与回调连接并导出结果

javascript - 执行 Express.js 中的所有函数后渲染模板

javascript - 通过拖动调整 Bootstrap 列的大小

javascript - NativeScript 中的 Paho MQTT

node.js - 错误: Can't set headers after they are sent after I have initialized a session

javascript - Node.js Express POST 请求未获取参数