next.js 未找到应用路由器迁移路由中的下一个Js API路由[重复]

b1zrtrql  于 2023-06-22  发布在  其他
关注(0)|答案(1)|浏览(125)

此问题已在此处有答案

How do you put api routes in the new app folder of Next.js?(3个答案)
6天前关闭

我试图调用nextJs API路由与新的应用路由特性。我总是找不到回来。我把结构做得像文档里一样。
这是我的chat.js文件,从来没有被调用?结构是否错误?
1.列表项

export default async function handler(req, res) {
    const {message} = req.body;

    try {
        const response = await axios.post(
            
        res.status(200).json(reply);
    } catch (error) {
        console.error(error);
        res.status(500).json({error: "An error occurred while processing the request"});
    }
gdx19jrr

gdx19jrr1#

和page.js一样,你的API路由必须被称为route.js。
所以在你的例子中,它会是这样的:API(文件夹)=>chat(文件夹)=>route.js(文件)
您可以在docs here中阅读更多信息。

相关问题