На этот вопрос уже есть ответ здесь:
Решение проблемы
В вашем _appфайле вам нужно
import App from "next/app"
а затем в том же файле при getInitialPropsвызове
const appProps = await App.getInitialProps(appContext)
Это будет работать getInitialPropsна отдельных страницах. Вы захотите перейти appPropsк основному компоненту в _app.
// _app.js
import App from "next/app"
const MyApp = ({ Component, pageProps }) => {
// whatever your main _app component looks like here
return (<Component {...pageProps } />)
}
MyApp.getInitialProps = async ({ ctx }) => {
// Stuff you want to do BEFORE loading props from the individual page
const appProps = await App.getInitialProps(appContext)
// Stuff you want to do AFTER loading props from the individual page
return {...appProps }
}
export default MyApp
Комментариев нет:
Отправить комментарий