nodejs之pathinfo/pathname的使用

228 阅读1分钟

 pathinfo/pathname风格参数如下: 例如: /detail/1/economy (detail/:id/:type)

<h1>这是列表页</h1>
<hr>
<ul>
    <li><a href="/detail/1">第1篇新闻标题</a></li>
    <li><a href="/detail/2">第2篇新闻标题</a></li>
    <li><a href="/detail/3">第3篇新闻标题</a></li>
    <li><a href="/detail/4">第4篇新闻标题</a></li>
</ul>

接口中:

app.get("/list", (req,res)=>{
    
    res.render("list")
})

app.get("/detail/:id", (req,res)=>{
    
    console.log(req.params);
    //let {id, type} = req.params;   // 解构获取多个
    //console.log(id, type);

    res.send(" detail ok! ");
    
})

\