简体   繁体   English

Mean.JS中的路由

[英]Routes in Mean.JS

I have a case where I need to expose the following server routes: 我遇到需要公开以下服务器路由的情况:

/cats/:catId /cats?name=:name / cats /:catId / cats?name =:名称

How should my server routes look? 我的服务器路由应如何显示? I tired this: 我很累:

app.route('/cats/:catId')
        .get(cats.read)

app.route('/cats?name=:name')
        .get(cats.getByName)

But that doesn't work. 但这是行不通的。 I seem to get routed to /cats in that case. 在这种情况下,我似乎被路由到了/ cats。

Should I have a route like this, or should I just do a switch in my server controller to handle the query strings as appropriate? 我应该拥有这样的路由,还是应该在服务器控制器中进行切换以适当地处理查询字符串?

you are getting into a route conflict, you are doing a fallback into the first route you are defining with the string cats , I'd would suggest to change the pattern if possible, to avoid it, follow a restful naming convention , it could be the case of: 您遇到路线冲突,正在回退到使用字符串cats定义的第一条路线,我建议您尽可能更改模式,以避免发生这种情况,请遵循一个宁静的命名约定 ,这可能是的情况下:

app.route('/cats/id/:catId').get(cats.read)
app.route('/cats/name/:name').get(cats.getByName)

does that makes sense? 这有意义吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM