第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

快速嵌套路由器不調(diào)用子功能

快速嵌套路由器不調(diào)用子功能

牛魔王的故事 2021-06-30 09:11:17
我的其中一臺路由器中有以下 router.use 調(diào)用router.use("/:collection/", (req) => {    return require(`./${req.params.collection}`);});在這個例子中調(diào)用,example.jsexample.js 如下:const header = require("../../header"); //gets our header that declares everythingconst router = header.express.Router(); //makes our router for collections requestsconsole.log("123");///The Following is when a name is requestedrouter.get("/test", (req, res, next) => {    console.log("test");    res.json({msg:"hi"});    next();});module.exports = router; //makes our router avialable你會期望什么時候:http://localhost:3000/api/example/test請求它會在控制臺中寫入以下內(nèi)容:123test我會得到回應(yīng):{msg:"hi"}相反,控制臺只得到:123寫了,沒有回應(yīng)。看來 router.get在 example.js 中從未被調(diào)用,有人能告訴我為什么嗎?
查看完整描述

1 回答

?
侃侃爾雅

TA貢獻(xiàn)1801條經(jīng)驗(yàn) 獲得超16個贊

我修復(fù)了它,而不是


router.use("/:collection/", (req) => {

    return require(`./${req.params.collection}`);

});


我用


router.get("/:collection", (req, res) => {

  //this is my other call that will do stuff in the parent file

  //we don't call next because it is already matched, otherwise we call next

});


router.use("/:collection/", (req, res, next) =>{ //says if it gets here pass on the info

  router.use("/:collection/", require(`./${req.params.collection}`)); //then route

  next();

});


查看完整回答
反對 回復(fù) 2021-07-08
  • 1 回答
  • 0 關(guān)注
  • 164 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號