當我嘗試使用/:user未在特定路由內運行的函式獲取資料時,誰能幫我弄清楚這里的錯誤是什么?
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
});
uj5u.com熱心網友回復:
由于結構,基本上你的/catalog和是相同的。值還可以。所以,嘗試不同的路由命名方法()。/:user:usercatalog/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
});
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/412072.html
標籤:
