Node.js |JS |每当我得到params.id,我就得到jumbotron.css
首先,这里是我的代码Node.js |JS |每当我得到params.id,我就得到jumbotron.css,node.js,parameters,Node.js,Parameters,首先,这里是我的代码 router .get('/find/:_id',(req,res)=>{ const id = req.params._id; console.log(id); if(id !== 'jumbotron.css'){ Doc.findById(id) .then((doc)=>{ res.render('table/content',{ title: doc.subject,
router
.get('/find/:_id',(req,res)=>{
const id = req.params._id;
console.log(id);
if(id !== 'jumbotron.css'){
Doc.findById(id)
.then((doc)=>{
res.render('table/content',{
title: doc.subject,
docs: doc
})
})
.catch((err)=>{
console.log(err)
})
}
});
这是输出
enterthe server running on 3000
Connected successfully to mongodb
5b00373bbea0a253106e0930
jumbotron.css
因此,每当我使用该Id生成GET req时,都会打印两项,
第一个是id,第二个是‘jumbotron.css’,
我不知道从哪里可以得到jumbotron.css作为req.params.id。
这不允许我进入该url。在您的
表格/内容
HTML上,您可能有:
<link rel="stylesheet" type="text/css" href="jumbotron.css">
而不是href=“/jumbotron.css”
或href=“/path/to/css/jumbotron.css”
由于它是相对于当前URL的,因此它正在执行以下请求:
/find/jumbotron.css
这就是为什么您会收到第二个id为“jumbotron.css”的请求。