终端中的警告基于未定义(阅读'use')-在我的应用程序中引入的路由是app〉router〉routers.js
const express = require("express");
const app = express();
const router = require("express").Router();
const { authRouters } = require("./Auth");
const { projectRouters } = require("./Project");
const { teamRouters } = require("./Team");
const { userRouters } = require("./User");
router.use("/project", projectRouters);
router.use("/team", teamRouters);
router.use("/user", userRouters);
router.use("/Auth", authRouters);
module.exports = { AllRouters: router };
团队. js(类似于项目. js、授权. js、用户. js)
const router = require("express").Router();
> my codes...
module.exports = { projectRouters: router };
最后在我的Server.js中
createRoutes() {
this.#app.get("/", (req, res, next) => {
return res.json({ message: "Welcome to my app" });
});
this.#app.use((error, req, res, next) => {
try {
this.#app.use(AllRouters);
} catch (error) {
next(error);
}
});
}
1条答案
按热度按时间des4xlb01#
他们也会面临类似的警告:问题的根源在于Server.js的contractor中没有定义“AllRouters”方法,解决方案为: