美文网首页
app.use 与 app.get区别

app.use 与 app.get区别

作者: 贝灬小晖 | 来源:发表于2018-08-22 16:10 被阅读18次

https://www.cnblogs.com/zjx2011/p/6376184.html

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

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

var express = require('express');
var app = express();

var index = require('./routes/index');

//1⃣️
app.use('/test1',function(req,res,next){
res.send('hello test1');
});
//2⃣️
app.get('/test2',function(req,res,next){
res.send('hello test2');
});
//3⃣️
app.get('/test3',index);
//4⃣️
app.use('/test4',index);

index是一个路由对象,结果,例1、2、4结果都能正确显示,而例3却报404。index.js很简单

相关文章

网友评论

      本文标题:app.use 与 app.get区别

      本文链接:https://www.haomeiwen.com/subject/dfsyiftx.html