反应+下一个js中未定义位置错误?

我正在尝试发送一些关于hosted url(部署我的构建的地方)的基本文本。但是我收到了这个错误
ReferenceError: location is not defined
here is my code

https://codesandbox.io/s/laughing-mendel-pf54l?file=/pages/index.js

export const getStaticProps = async ({ preview = false, previewData = {} }) => {
  return {
    revalidate: 200,
    props: {
      //req.host
      name: location.hostname == "www.google.com" ? "Hello" : "ccccc"
    }
  };
};

回答

你能显示你的进口,因为这可能是你从进口路由器 'next/client'

假设您正在使用基于功能的组件

您需要按如下方式导入路由器:

import {useRouter} from "next/router";

在你的函数体中:

const router = useRouter();


以上是反应+下一个js中未定义位置错误?的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>