Intro
I'm building an app with next.js. Using its static site generation. For some reason the params object in getStaticProps is empty. I've read the examples and docks for the last few hours and cannot see why the cause. Perhaps someone with more next experience can spot the problem.
/pages/projects/[id].js
export async function getStaticPaths() {
return {
paths: [
{ params: { id: '1' } },
],
fallback: false
};
}
export async function getStaticProps({params}) {
console.log(params); // params is just an empty object
const { data: projectData } = await axios(`${CMS_URL}/projects/${params.id}`);
console.log(projectData);
return {
props: {
...projectData,
}
};
}
export default function ProjectDetailPage(props) { ...
next.config.js
...
exportPathMap: async () => {
const paths = {
'/': { page: '/' },
'/blog': { page: '/overview' },
};
const { data: projectsData } = await axios(`${apiUrl}/projects`);
projectsData.forEach(project => {
paths[`/projects/${project.id}`] = { page: '/projects/[id]', query: { id: project.id } };
});
console.log(paths);
/*
{
'/': { page: '/' },
'/blog': { page: '/overview' },
'/projects/1': { page: '/projects/[id]', query: { id: 1 } }
}
*/
return paths;
}
...
Question
I've added the correct folder structure, and exportPathMap. Also added the static path and props to my component. I cant see why the params object is empty. Can you tell me why it is not working?
