我想将参数传递给页面。但是有404。我的代码:
应用程序.js
var routes = require('./routes/index');
var app = express();
路线/index.js:
var express = require('express');
var router = express.Router();
router.get('/profile/:id', function (req, res) {
var id = req.params.id;
console.log(id);
res.render('profile', {id: id});
});
我尝试http://localhost:3000/profile?id=56e2c3c2cdde3f64302ac154但有错误:未找到
最佳答案
您的路线应如下所示:
http://localhost:3000/profile/56e2c3c2cdde3f64302ac154
它会自动设置req.params.id
。
关于javascript - 带参数的 Node js 路由器 404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35955499/