簡體   English   中英

GET方法不適用於ExpressJS中的特定路線

[英]GET method not working on specific route in ExpressJS

當我嘗試使用/:user獲取數據時,function 沒有在特定路由中運行,誰能幫我弄清楚這里的錯誤是什么?

const express = require("express");
const app = express();
const mongoose = require("mongoose");
const {accountSC,catalogSC} = require("./schema");

let dburl = **database url**
app.use(express.json());
mongoose.connect(dburl);

app.get("/catalog", async (req, res) => {
  //some func inside it
});

app.get("/:catalog/:id", async (req, res) => {
    //some func inside it
});

app.get("/:user", async (req, res) => {
    //some func inside it
});

基本上您的/catalog/:user由於結構相同。 :user值也可以是catalog 因此,嘗試不同的路由命名方法( /info/:user )。

謝謝你。

更新:試試這個。

app.get("/catalog", async (req, res) => {
  //some func inside it
});

app.get("/catalog/:catalog/:id", async (req, res) => {
    //some func inside it
});

app.get("/info/:user", async (req, res) => {
    //some func inside it
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM