Next.js 如何重定向到外部页面?

Next.js 如何重定向到外部页面?,next.js,Next.js,所以,当我的站点返回400时,我需要重定向到外部页面。我尝试过按照Next.js重定向教程进行操作,但没有成功,我尝试过使用window.locate,但在生产中破坏了我的站点。 以下是我尝试过的代码: import React from 'react' import Router from 'next/router' export default class extends React.Component { static async getInitialProps({ res }) {

所以,当我的站点返回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的缺点。路由工作不好。 我以前遇到过同样的问题,但后来又改回了reactjs


亲切问候

我不知道为什么会发生这种情况,这种问题在他们的github中有很多请求,但他们从未解决过。。。哦,好吧。。。