我有一个帆应用程序,我正在尝试加载一个页面,其中包含一些数据库中的数据,基于
id
的
recipe
模型。
我有路线
'GET /recipes/single-recipe/:id': { action: 'recipes/view-single-recipe' }
设置并访问URL
http://localhost:1337/recipes/single-recipe/5b8c169936f1df3439fa39c7
在我的
view-single-recipe
操作我试图通过访问URL参数的ID加载配方
req.param('id')
但是
req
显示未定义。
//view-single-recipe.js
module.exports = {
friendlyName: 'View single recipe',
description: 'Display "Single recipe" page.',
exits: {
success: {
viewTemplatePath: 'pages/recipes/single-recipe'
}
},
fn: async function(inputs, exits) {
const recipe = await Recipe.find({
id: req.param('id') //req undefiend
});
// Respond with view.
return exits.success({
recipe: recipe
});
}
};
获取错误:
error: Sending 500 ("Server Error") response:
ReferenceError: req is not defined
如何使用url参数加载正确的配方?