我创建了多个动态页面(例如:/Pages/[Product]/[Product].js),在不使用“使用客户端”的情况下与下面的页面结构配合得很好。能够作为 ssr 运行,能够使用状态或钩子。
export async function getServerSideProps(context) {
return fetch(data)
}
class Product extends Component {
constructor(props) {
super(props);
this.state = {
data = this.props.data
}
render() {
return(<></>)
}
}
但是当涉及常规页面(例如:src/App/page.js 或 src/page.js)时,那些单页面(例如主页)。说我不能使用类组件..
您正在导入一个类组件。它仅适用于客户端 组件,但其父组件均未标记为“使用客户端”,因此 默认情况下它们是服务器组件。
我可以使用“使用客户端”绕过,但随后我无法使用 getServerSideProps 并使用 srr 渲染页面。
有没有办法让单页面与类组件和 getServerSideProps 一起使用,就像那些动态页面一样?