如何重定向到外部页面?

时间:2019-10-16 22:02:06

标签: 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 }) {
    if (res) {
      res.writeHead(302, {
        Location: 'http://google.com'
      })
      res.end()
    } else {
      Router.push('/')
    }
    return {}
  }
}

还有没有window.locate方法的另一种解决方案? 谢谢!

1 个答案:

答案 0 :(得分:0)

实际上是next.js的不好的一面,路由无法正常工作。 我遇到了同样的问题,然后才将其改回reactjs

亲切的问候