1 回答

TA貢獻(xiàn)1836條經(jīng)驗 獲得超4個贊
Next Js Docs幫助找出錯誤。這是你出錯的地方。您以這種格式傳遞了一組對象:
[{id:1}, {id:2}]
當(dāng) getStaticPaths 期待這個時:
[
{ params: { id: '1' } },
{ params: { id: '2' } }
]
解決方案:
export async function getStaticPaths() {
const apiDataPaths = await getApiDataPaths();
// Empty arr to build new paths
const newPaths = [];
// Add params to every slug obj returned from api
for (let slug of apiDataPaths) {
newPaths.push({ params: { ...slug } });
}
// Return paths to render components
return {
paths: newPaths,
fallback: true
};
}
您還可以考慮清理服務(wù)器端的數(shù)據(jù)。
添加回答
舉報