node.js - 即使从后端重定向后页面也不会刷新
问题描述
我有一个注册页面的 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 }
即使它在网络选项卡上重定向,它也没有在实际页面上重定向,有人可以帮助我吗?
解决方案
我使用下面的代码来解决这个错误
fetch(req).then((res) => {
console.log(res);
response.json().then((data) => {
console.log(data);
});
});
推荐阅读
- amazon-redshift - Redshift:每天更改表的名称
- css - 如何在 WKWebView 中使用 URL 加载 CSS 文件
- tmux - 哦,我的 zsh 在 tmux 上显示奇怪的空白区域
- c - fgets 总是在文件的第一行读取 3 个垃圾字符
- vb.net - vb.net 中的进度条
- ios - 显示 tableView 时,如何将 tableView 单元格排列为不同的顺序?
- java - Docker 无法连接到主机,端口:smtp-mail.outlook.com,587
- html - 如何在 CSS 中悬停/单击时为宽度大小设置动画?
- bash - 可以在bash中按给定日期对进程进行排序吗?
- flutter - 屏幕溢出