Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/390.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Node.js-使用母版/详细页在Express中重定向_Javascript_Node.js_Express - Fatal编程技术网

Javascript Node.js-使用母版/详细页在Express中重定向

Javascript Node.js-使用母版/详细页在Express中重定向,javascript,node.js,express,Javascript,Node.js,Express,我正在学习Node.js。为了学习,我正在构建一个基本的应用程序。此时,我正在尝试创建母版/详细页。这是母版页 /views/master.ejs <html> <body> [items would go here] <a href="/new">add new</a> </body> </html> <html> <body> <form id="myF

我正在学习Node.js。为了学习,我正在构建一个基本的应用程序。此时,我正在尝试创建母版/详细页。这是母版页

/views/master.ejs

<html>
  <body>
    [items would go here]
    <a href="/new">add new</a>
  </body>
</html>
<html>
  <body>
    <form id="myForm" method="post" action="/new">
      <button type="submit">Submit</button>
    </form>
  </body>
</html>
如何处理母版详细信息页面场景中的加载视图


谢谢

看起来你想在帖子中重定向。如果希望在POST请求后呈现主页,只需呈现预期结果即可

/* POST new item */
router.post('/new', function(req, res) {
    // do server stuff ...

    res.render('master'); 
});

我认为使用下面的代码可能会有所帮助

router.post('/new', function(req, res) {
console.log('creating item...');
res.redirect('/');   // if you don`t specify status defaults to 302 found
});

查看此链接:

您是否尝试过在不传递视图模型的情况下重定向?例如:

res.redirect('/projects/setup/website/details');

中的所有示例均未显示正在传递的视图模型。

您使用的是哪个版本的express?我不认为
redirect
接受第三个参数@azium我使用的是4.9.0在用户单击“提交”按钮后,我希望他们加载“主”视图。此外,其浏览器地址栏中的URL应为“/”。据我所知,你所展示的方法不会对后者起作用。运气不好。我一直收到一个“404”错误。奇怪的是,它在控制台窗口中附加了“200”,我看到:
GET/2004043.453ms-90
我不知道200是从哪里来的。啊哈!我应该更加关注这些文件。谢谢你的帮助。
res.redirect('/projects/setup/website/details');