在 Express MDN 教程中创建新路由时出现 404

问题描述 投票:0回答:1

我正在尝试 MDN Express 教程第 2 部分中的自我挑战部分。创建 Express 项目后,他们会提出以下问题:

/routes/users.js
中创建一条新路线,该路线将在 URL /users/cool/ 处显示文本“You're so Cool”。通过运行服务器并访问来测试它

http://localhost:3000/users/cool/ 
在您的浏览器中

我已经尝试过,但不断收到 404 错误

 var express = require('express');
 var router = express.Router();

 /* GET users listing. */
 router.get('/', function(req, res, next) {
   res.send('respond with a resource');
 });

 // this was for the challenge youself portion, to create something that appears at   /users/cool...but it wont work

 router.get('/cool', function(req, res, next) {
   res.send('You are so cool!');
 });

 module.exports = router;
express routes http-status-code-404
1个回答
0
投票

Express 正在收听

/cool
,而不是
/users/cool
。这就是
404
误差的平均值。请务必阅读 Express 路由文档,此处此处

© www.soinside.com 2019 - 2024. All rights reserved.