簡體   English   中英

在Express.js中路由

[英]Routing in Express.js

我目前在Node.js中表示路由器,並且遇到如下問題。 假設我有兩個網址; 一種是獲取用戶信息,另一種是將用戶注冊到應用程序。

http://example.com/users/:idUser (這將提供用戶信息)

http://example.com/users/registration (這將允許用戶注冊)

我面臨的問題是當我致電注冊時,路由器正在使用idUser 所以我不得不像user/registration而不是users一樣進行編輯。 如果要用作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) {
   ....
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM