app.use 与 app.get区别

2018-08-22  本文已影响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很简单

上一篇 下一篇

猜你喜欢

热点阅读