在 Express.js 中路由
Routing in Express.js
我目前在 Node.js 中使用快速路由器,遇到如下问题。假设我有两个 url;一种是获取用户信息,一种是将用户注册到应用程序。
http://example.com/users/:idUser (this will give a information of a user)
http://example.com/users/registration (this will allow a user registration)
我遇到的问题是,当我调用注册时,路由器正在使用 idUser
;所以我不得不像 user/registration
而不是 users
那样编辑。如果我想使用as users/registration
,我需要做哪些工作。我在Node.js.
还是新手
谢谢。
把顺序倒过来,像这样:
app.get('/users/registration', function(req, res, next) {
...
});
app.get('/users/:userId', function(req, res, next) {
...
});
您需要对路由进行适当排序,以便注册路由在前。
app.get('/users/registration', function(req, res, next) {
....
});
app.get('/users/:userId', function(req, res, next) {
....
});
我目前在 Node.js 中使用快速路由器,遇到如下问题。假设我有两个 url;一种是获取用户信息,一种是将用户注册到应用程序。
http://example.com/users/:idUser (this will give a information of a user)
http://example.com/users/registration (this will allow a user registration)
我遇到的问题是,当我调用注册时,路由器正在使用 idUser
;所以我不得不像 user/registration
而不是 users
那样编辑。如果我想使用as users/registration
,我需要做哪些工作。我在Node.js.
谢谢。
把顺序倒过来,像这样:
app.get('/users/registration', function(req, res, next) {
...
});
app.get('/users/:userId', function(req, res, next) {
...
});
您需要对路由进行适当排序,以便注册路由在前。
app.get('/users/registration', function(req, res, next) {
....
});
app.get('/users/:userId', function(req, res, next) {
....
});