reactjs - 如何使用 getServerSideProps 将用户重定向到另一个页面?
问题描述
我找到了这个解决方案:
export const getServerSideProps = async ({ res }) => {
res.redirect(301, '/another-page')
return {
props: {}
}
}
但我没有看到redirect
方法res
并得到一个错误
解决方案
好像您正在使用 Next.js。尝试这样的事情。
export const getServerSideProps = async ({ res }) => {
res.setHeader("location", "/another-page")
res.statusCode = 301
res.end()
return;
}
推荐阅读
- java - 在 Spring 应用程序中找不到 OptaPlanner SolverManager Bean
- postgresql - 无法使用 Entity Framework Core 3.1.3 更新数据库
- python - 如何允许多个线程同时修改一个类的变量
- c++ - Xcode:错误:预期的'('用于函数样式转换或类型构造
- angular - 如何在水龙头中查看 json 的值
- asp.net - 读取 DataTable 时获取意外的 JSON 令牌。预期 StartArray,得到 StartObject 错误
- python - 如何遍历两个不同大小的数组并对python中的每个数组执行不同的操作
- python - 创建组和某些字符后跟数字时,Python regex 挂起
- reactjs - G2Plot AntV 库。自定义子弹图工具提示(显示名称而不是索引)
- c# - 如何访问数据库上下文接口的数据库字段?