예제 라우터 : user/1, user/2... 등 유저 상세페이지 만들기
RgProject.getInitialProps = async (context) => {
const { ctx, Component } = context;
let pageProps = {};
if (Component.getInitialProps) {
pageProps = await context.Component.getInitialProps(ctx);
}
return {pageProps};
};
import React from 'react';
import PropTypes from 'prop-types';
const User = ({ id }) => {
return (
<>
user 정보 {id}
</>
)
};
User.PropTypes = {
id : PropTypes.number.isRequired,
};
User.getInitialProps = async (context) => {
console.log('user id getInitialProps', context.query.id)
return { id : parseInt(context.query.id, 10)}
};
export default User;
RgProject.getInitialProps = async (context) => {
console.log('context', context)
const { ctx, Component } = context;
let pageProps = {};
if (Component.getInitialProps) {
pageProps = await context.Component.getInitialProps(ctx);
}
return {pageProps};
};
const RgProject = ({ Component, store, pageProps }) => {
return (
<Provider store={store}>
<Head>
<title>냉장고 지도</title>
</Head>
<AppLayout>
<Component {...pageProps} />
</AppLayout>
</Provider>
)
};
const User = ({ id }) => {
return (
<>
user 정보 {id}
</>
)
};