React加载页面时抛出此错误:
无法在“历史记录”上执行“ replaceState”:无法在源为“ https:// ***”的文档中创建URL为“ https:// ***** g / poclogin”的历史记录状态对象** g.gg'和URL'https:// ***** g / poclogin'。
我正在使用Next.js和React。加载时,我正在路由到Router.push("/poclogin")
。它在开发中工作正常,但在生产中却抛出了错误。
这是我的index.tsx
import * as React from "react";
import Router from "next/router";
import "../public/scss/general.scss";
import "../public/scss/style.css";
export default class extends React.Component {
static async getInitialProps({ res }) {
if (res) {
res.writeHead(302, {
Location: "/poclogin"
});
res.end();
} else {
Router.push("/poclogin");
}
return {};
}
}