【发布时间】:2019-10-17 06:19:53
【问题描述】:
所以,当我的网站返回 400 时,我需要重定向到外部页面。我尝试按照 Next.js 重定向教程进行操作,但没有成功,我尝试使用 window.locate,但会破坏我的网站在生产中。 这是我尝试过的代码:
import React from 'react'
import Router from 'next/router'
export default class extends React.Component {
static async getInitialProps({ res }) {
if (res) {
res.writeHead(302, {
Location: 'http://google.com'
})
res.end()
} else {
Router.push('/')
}
return {}
}
}
没有window.locate 方法还有其他解决方案吗? 谢谢!
【问题讨论】:
标签: next.js