I use routing in app.js
var headbarRouter = require("./routes/headbar");
app.use("/headbar", headbarRouter);
then write this in routes/headbar.js
router.get("/", function(req, res, next) {
console.log("--------")
res.render("headbar", { title: "Express" });
});
my understanding is that requests that start with headbar will be intercepted, and then render to headbar.ejs
, but that"s what I wrote in index.ejs
<script src="/headbar.js"></script>
isn"t this also a request? Why did you not intercept and go to headbar.ejs, but reported an error of 404
?