当我点击card.pug文件中的答案链接时,我得到了404.
extends layout.pug
block content
section#content
h2= text
if hint
p
i Hint: #{hint}
a(href=`${id}?side=${sideToShow}`)= sideToShowDisplay
card.pug文件的路由文件如下:
const express = require('express');
const router = express.Router();
const { data } = require('../data/flashcardData.json');
const { cards } = data;
router.get('/:id', (req, res) => {
const { side } = req.query;
const { id } = req.params;
const text = cards[id][side];
const { hint } = cards[id];
const templateData = { id, text };
if (side === 'question') {
templateData.hint = hint;
templateData.sideToShow = 'answer';
templateData.sideToShowDisplay = 'Answer';
} else if (side === 'answer') {
templateData.sideToShow = 'question';
templateData.sideToShowDisplay = 'Question';
}
res.render('card', templateData);
});
module.exports = router;
我不确定为什么会这样做。任何帮助将非常感激。它从数据文件夹中的JSON文件中提取数据。
答案 0 :(得分:-1)
您可以使用锚点href = ' user single code here'
示例
a(href=`${id}?side=${sideToShow}`)= sideToShowDisplay
代替上面的用法
a(href='${id}?side=${sideToShow}')= sideToShowDisplay
对我有用