简体   繁体   English

在此代码中注册后如何重定向到登录页面

[英]How can I redirect to login page after registration in this code

every help me :(((. here is link to my code https://github.com/tranluongtiensi/registration_system每一个帮助我:(((。这里是我的代码的链接https://github.com/tranluongtiensi/registration_system

I want to redirect the user to login page after registration, I have tried many ways but it doesn't work.我想在注册后将用户重定向到登录页面,我尝试了很多方法但它不起作用。 thank everyone very much非常感谢大家

You can just use the window.location.href when you submit your signup form.提交注册表单时,您可以只使用window.location.href So your code for registerUser(...) would look something like this.所以你的registerUser(...)代码看起来像这样。

async function registerUser(event){
      event.preventDefault()
      const username = document.getElementById('user').value
      const password = document.getElementById('password').value
      const password_confirmation = document.getElementById('password_confirmation').value
      const phone = document.getElementById('tel').value

      const result = await fetch('/register',{
         method: 'POST',
         headers: {
           'Content-Type': 'application/json'
         },
         body: JSON.stringify({
           username,
           password,
           password_confirmation,
           phone
         })
      }).then((res) => res.json())

      if (result.status === 'ok') {
         alert('success');
         // on a successful signup, redirect user to the login page
         window.location.href = 'LINK_TO_SIGNIN_PAGE'; // exp. http://localhost/signin.html
      }else {
        alert (result.error)
      }
    }

Give it a go!搏一搏!

You need to add a redirect here to this line here您需要在此处添加重定向到此行

for example :例如 :

window.location.href = 'login.html'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 注册后如何让 React 应用重定向到登录页面? - How do i make a react app redirect to the login page after registration? 如果未处于登录状态并且登录后重定向到原始页面,如何重定向到登录页面? - How do I redirect to login page if not in logged in state and after login redirect to the original page? 使用Google登录表单登录后,如何将用户重定向到新页面? - How can I redirect users to a new page after they logged in with the Google login form? 完成注册表后,我如何显示“您已完成”的提示。 单击“确定登录”,然后当用户单击“确定”时它会转到登录页面? - After complete an registration form, how can i show an alert 'Your are done. click OK to login' and then when user click OK it will go to login page? 如何在 React js 中将登录重定向到当前页面? - How can I redirect login to current page in react js? 如何从登录页面到索引创建登录代码? - how I can make a login code from the login page to the index? 成功登录后如何重新加载/重定向页面? - How to reload / redirect page after successful login? 登录后如何重定向到主页:ReactJS? - how to redirect to home page after login: ReactJS? 登录成功后如何重定向到一个页面:ReactJS? - how to redirect to a page after successful login: ReactJS? ReactJS成功登录后如何重定向到页面? - how to redirect to a page after successful login in ReactJS?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM