首页 > 解决方案 > 即使从后端重定向后页面也不会刷新

问题描述

我有一个注册页面的 Web 应用程序的发布请求,我想将该页面呈现到前端,我的注册页面如下所示:

const CustomAPIError = require('../../errors/customError')
//import jsonwebtoken for using jwt to issue token from the server to send secret to the user
const jwt = require('jsonwebtoken')
require('dotenv').config()


const login = async (req, res) => {
  res.status(200).json({ msg: 'logged in' })
}

const createsignupuser = async (req, res) => {
  const { Firstname, Lastname, Email, password, confirmPassword, username } = req.body
  if (!Firstname || !Lastname || !Email || !password || !confirmPassword || !username) {
    throw new Error("please provide appropriate credentials", 400)
  }

  if (password !== confirmPassword) {
    throw new Error('password does not match')
  }

  return res.status(200).redirect('/login')
}




module.exports = { createsignupuser, login }

即使它在网络选项卡上重定向,它也没有在实际页面上重定向,有人可以帮助我吗?

标签: node.jsexpress

解决方案


我使用下面的代码来解决这个错误

fetch(req).then((res) => {
  console.log(res);
  response.json().then((data) => {
    console.log(data);
  });
});

推荐阅读