You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

点击card.pug内答案链接触发404错误,寻求技术排查帮助

Hey there, let's break down why you're hitting that 404 error when clicking the answer link in your card.pug file. Since you mentioned the data pulls from a JSON file in the data folder, here are the most common issues to troubleshoot step by step:

First, inspect the actual link generated in your rendered HTML. Right-click the link in your browser and select "Inspect" to see what the href attribute is set to.

  • If you're pulling a path/ID from your JSON data (like a(href='/answers/' + item.answerId) View Answer), make sure the concatenated path matches exactly what your routes are expecting.
  • Watch out for missing slashes or extra segments—for example, if your route is /answers/:id, a link to /answer/123 (missing the 's') will throw a 404.

2. Validate your route configuration

Even without seeing your route file, let's cover the key checks for typical setups (like Express.js, which is common with Pug):

  • Ensure your route defines the correct path. If your link points to /answers/456, your route should look something like router.get('/answers/:id', (req, res) => { ... }).
  • Confirm the route is properly mounted in your main app file. For example, if your routes are in routes/answers.js, you need a line like app.use('/answers', require('./routes/answers')) in app.js—a wrong mount path here will break all requests to that route.

3. Check your JSON data for errors

Open the JSON file in your data folder and verify the values you're using for the answer links:

  • If you're using an ID parameter, make sure the answerId (or whatever field you're using) exists for every entry and doesn't have typos.
  • If the JSON stores full paths, ensure those paths align with your server's route structure—outdated or incorrect paths here will lead directly to 404s.

4. Watch for case sensitivity and typos

This is a super common culprit, especially on Linux-based servers:

  • Route paths are case-sensitive. A link to /Answers/123 won't match a route defined as /answers/:id.
  • Double-check for misspellings (e.g., answr instead of answer) in both your Pug template and route definitions.

5. Test the route directly

Skip the card link entirely and type the expected route URL directly into your browser's address bar (like http://localhost:3000/answers/1).

  • If this also returns a 404, the problem is definitely in your route setup or server configuration.
  • If it works, the issue is in how you're generating the link in card.pug.

If you can share snippets of your route code, the link section from card.pug, or a sample of your JSON data, we can narrow this down even further.

内容的提问来源于stack exchange,提问作者AltBrian

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 09:07:27