Express routing related issues

  node.js, question

Very simple question, I send a request from the client, assuming post.
Then the back-end performs relevant processing according to the path.

app.use('/login', users);  //The path is /login. Give users this route file.
 
 //The following is the code in users
 Post ('/login', function (req, res, next) {//will report to 404 error
 res.send('respond with a resource');
 });
 
 
 Router. post ('/',function (req, res, next) {//can return data normally. I don't quite understand the reason.
 res.send('respond with a resource');
 });

These are my problems. I checked the relevant documents, but failed to find out. I hope you can help me and give me some advice.

Judging from inside’s code, the original code looks like this.

  1. app.use('/login', users);This line of code means that as long as the paths match/login, then control is given to user

  2. When you come to the route defined on user, the/loginThis prefix is removed before route matching. So when you visit/loginPost (‘/’,fn) will be hit.

Why did you do this? Imagine that one day, the address prefix you visit changes from/loginBecome/login2, then, you just need to change a place. exactlyapp.use('/login2', user).

var user = express.Router();
 
 user.post('/login', function(req, res, next) {
 res.send('respond with a resource');
 });
 
 user.post('/', function(req, res, next) {
 res.send('respond with a resource');
 });
 
 app.use('/login', users);