Express 主索引路由正在工作,其他所有路由都不工作
有人能帮我弄清楚为什么我的快车路线不起作用吗。我花了好几天的时间试图解决这个问题,但当我访问customer.js中的任何一条路由时,我总是会遇到404个错误 我的一个路由文件下面唯一有效的路由文件是索引路由器。Express 主索引路由正在工作,其他所有路由都不工作,express,Express,有人能帮我弄清楚为什么我的快车路线不起作用吗。我花了好几天的时间试图解决这个问题,但当我访问customer.js中的任何一条路由时,我总是会遇到404个错误 我的一个路由文件下面唯一有效的路由文件是索引路由器。 var express=require('express'); var router=express.router(); router.get('/customers',函数(req、res、next){ console.log(请求状态()) res.send(“一些html”);
var express=require('express');
var router=express.router();
router.get('/customers',函数(req、res、next){
console.log(请求状态())
res.send(“一些html”);
});
路由器.post('/customers/update/shipping',函数(req,res){
res.send(“someghtml”);
});
路由器.post('/customers/update/billing',函数(req,res){
res.send(“somew html”);
});
router.post('/customers/update/cart',函数(req,res){
res.send(“一些dhtml”);
});
module.exports=路由器;
在您的客户文件中,您的路线已经与
/customers
相关。从所有路线中删除领先的/customers
。例如:
router.get('/customers', function(req, res, next) {
console.log(req.status())
res.send('<p>some html</p>');
});
router.get('/customers',函数(req、res、next){
console.log(请求状态())
res.send(“一些html”);
});
应该是
router.get('/', function(req, res, next) {
console.log(req.status())
res.send('<p>some html</p>');
});
router.get('/',函数(req,res,next){
console.log(请求状态())
res.send(“一些html”);
});
同样的原则也适用于其他文件。wow!非常感谢Mkantjwa先生!!!!你是个救生员!!!。这是今天到期的学校作业,已经被卡住了好几天。嘿,对不起,还有一个问题,当我删除/客户时,其他客户路线不起作用。注意,其他是POST请求。因此,请确保您正在
POST
ing到您的API。这很好。如果它们不需要是post请求,那么您可以简单地将它们更改为路由器。出于礼貌,请接受他的回答,如果它确实对您有帮助的话!
router.get('/customers', function(req, res, next) {
console.log(req.status())
res.send('<p>some html</p>');
});
router.get('/', function(req, res, next) {
console.log(req.status())
res.send('<p>some html</p>');
});