我正在 next.js 和 mongodb 网站上工作,我完全遵循本教程,但使用不同的文件/变量名称。我在尝试访问动态页面时不断遇到此错误:错误:未在 getStaticPaths 中为 /location/[id] 提供所需参数 (id) 作为字符串
教程:https ://www.youtube.com/watch? v=MFuwkrseXVE&ab_channel=Academind 就在 2 小时 40 分钟之前
PS出于安全原因删除了数据库信息
export async function getStaticPaths(){
const client = await MongoClient.connect(''); ////////// username and password here for mongo db and db name
const db = client.db();
const destinationsCollection = db.collection('destination');
const destinations = await destinationsCollection.find({},{_id: 1}).toArray();
client.close();
return {
fallback: false,
paths: destinations.map((destination) => ({ params: {destinationId: destination._id.toString()},
})),
};
}
Run Code Online (Sandbox Code Playgroud)