小编Jac*_*ant的帖子

错误:未在 /location/[id] 的 getStaticPaths 中以字符串形式提供必需的参数 (id)

我正在 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)

mongodb node.js next.js

2
推荐指数
1
解决办法
3630
查看次数

标签 统计

mongodb ×1

next.js ×1

node.js ×1