如何重定向到 node.js 中的另一个页面 [英] How to redirect to another page in node.js

查看:37
本文介绍了如何重定向到 node.js 中的另一个页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个登录和注册页面.当随机用户想要登录并且登录成功时,我想将他重定向到另一个 .ejs 页面(例如 UserHomePage.ejs),但是,到目前为止,我尝试过的一切都没有奏效.

I have a login and a signup page. When random user wants to login, and login is successful, I want to redirect him to another .ejs page (for example UserHomePage.ejs), however, nothing I've tried have worked so far.

if (loggedIn)
    {
        console.log("Success!");
        res.redirect('/UserHomePage');
    }
    else
    {
        console.log("Error!");
    }

我也想知道,如何在按钮点击时重定向用户.

I would also like to know, how to redirect a user on button click.

假设我在显示用户页面上,在那里我显示了我的所有用户,然后是添加另一个使用过的按钮".我怎么做?onclick 后如何将用户重定向到 Register.js 页面?

Let's say I'm on display user page, where I display all of my users, then there is "add another used button". How do i do that? How do I redirect user to Register.js page after onclick?

<h2>List of users</h2>
<ul>
<% uporabniki.forEach(function(user) { %>
<li>  
  <%= user.attributes.name %>
  <%= user.attributes.last name %>
</li>
<% }); %>
</ul>
<h3>Add another user</h3>
<form method="post">
 <input type="submit" value="Add user" />
</form>

推荐答案

你应该返回重定向的行

return res.redirect('/UserHomePage');

这篇关于如何重定向到 node.js 中的另一个页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆