【问题标题】:How to redirect to a external page?如何重定向到外部页面?
【发布时间】: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


    【解决方案1】:

    这确实是 next.js 的不好的一面,路由不能正常工作。 我之前遇到了同样的问题,然后我把它改回 reactjs

    亲切的问候

    【讨论】:

    • 我不知道为什么会这样,这种问题在他们的github上有很多请求,但他们从来没有解决过......哦,好吧......
    猜你喜欢
    • 1970-01-01
    • 2022-06-18
    • 2013-03-11
    • 1970-01-01
    • 2015-06-13
    • 2018-01-08
    • 1970-01-01
    • 1970-01-01
    • 2013-09-19
    相关资源
    最近更新 更多