在我的自定义nextJs应用getServerSideProps
中,永远不会在页面中调用。
这是我的pages/_app
目录的内容:
AuthWrapper:
const AuthWrapper = (props) => {
//some auth logic
return (
<LayoutWrapper {...props} />
)
}
export default AuthWrapper
LayoutWrapper:
const LayoutWrapper = ({ Component, pageProps }) => {
return (
<Layout style={{ minHeight: '100vh' }}>
<Layout>
<Header />
<Content >
<Component {...pageProps} />
</Content>
<Footer style={{ textAlign: 'center' }}>ABC, Inc.</Footer>
</Layout>
</Layout>
)
}
LayoutWrapper.propTypes = {
Component: PropTypes.node,
pageProps: PropTypes.object
}
export default LayoutWrapper
应用程序:(index.js)
const App = (props) => {
return (
<Auth0Provider
//someProps
>
<Provider store={props.store}>
<AuthWrapper {...props} />
</Provider>
</Auth0Provider>
)
}
App.propTypes = {
store: PropTypes.any
}
export default withRedux(initStore)(App)
现在在我的自定义页面中:
pages/myPage/index.js
const MyPage = ({ data }) => {
return (
<>
{/* someHtml */}
</>
)
}
MyPage.propTypes = {
data: PropTypes.string
}
export const getServerSideProps = async () => {
console.log("inside getServerSideProps method")
return { props: { data: "Hello World" } };
}
export default React.memo(MyPage)
getServerSideProps
永远不会被调用
确保所有文件中的所有导入均正确完成