nodejs之express(二)路由中间件router实现路由

 路由级中间件和应用级中间件一样,只是它绑定的对象为 express.Router()。
var router = express.Router();

app.use(path,callback)中的callback既可以是router对象又可以是函数;

app.get(path,callback)中的callback只能是函数;

路由规则是app.use(path,router)定义的,router代表一个由express.Router()创建的对象,在路由对象中可定义多个路由规则;当一个路径有多个匹配规则时,使用app.use,否则使用相应的app.method(get、post);

app.use内部其实调用了router.use,









猜你喜欢

转载自blog.csdn.net/u011146511/article/details/80680598