node.js的动态路由 https://blog.csdn.net/hust_cxl/article/details/79929093(具体参考此文最佳)
var express = require(‘express’); var app = new express();
app.get(’/’,function (req,res) { res.send(“hello express”); })
app.get(’/news’,function (req,res) { res.send(“hello news”); })
//动态路由 http://localhost:8001/newscontent/1243 app.get(’/newscontent/:aid’,function (req,res) {
//req.params获取动态路由的传值
var aid = req.params.aid; //aid = 1243
res.send("hello newscontent"+"------"+aid);
}) //获取get传值 http://localhost:8001/product?aid=1234567 app.get(’/product’,function (req,res) { var aid = req.query.aid; res.send(“hello product----”+aid); }) app.listen(‘8001’,‘127.0.0.1’);