Reputation: 397
I want my routes to be like the following:
/
/business
/business/stuff1
/business/stuff2
/business/admin
for /business
I want to have a separate file for the routing and functions.
and also for /business/admin
I want to have a separate file for the routing and functions.
so what I did is: app.js
//Business route
const business = require("./business/business");
app.use("/business", business);
This works fine - but when I add in business.js
//admin route
const admin = require("./admin");
app.use("/admin", admin);
I get 404 for some reason.
Upvotes: 0
Views: 39
Reputation: 9116
Depends on what you are exporing from business.js
. It should be an instance of express.Router and you have to mount the /admin
route on this instance. Example:
// business.js
const admin = require("./admin");
const businessApp = express.Router();
businessApp.use("/admin", admin);
module.exports = businessApp;
Upvotes: 1