简体   繁体   English

express.js路由

[英]express.js routing

Do these two express.js routes match? 这两个express.js路由匹配吗?

/:campus/:tlf_id/message
/:campus/:message_id/reply

In express.js it seem that the do. 在express.js中,似乎可以做到。 I'm not sure I understand this correctly. 我不确定我是否正确理解。

That is, if requesting /12/90/reply might it be caught by /:campus/:tlf_id/message ? 也就是说,如果请求/12/90/reply /:campus/:tlf_id/message /12/90/reply可能会被/:campus/:tlf_id/message捕获?

They don't match because the 3rd url part is not prefixed with a colon. 它们不匹配,因为第3个url部分没有前缀冒号。 The colon prefix on the first 2 turns them into a named parameters and match anything other than / . 前2个冒号前缀将它们转换为命名参数,并匹配/以外的任何内容。 The 3rd part will be a required match. 第三部分将是必填项。 So the over simplified RegEx for the routes would be /([^/]+)/([^/]+)/message and /([^/]+)/([^/]+)/reply . 因此,路由的过度简化的RegEx将是/([^/]+)/([^/]+)/message/([^/]+)/([^/]+)/reply

它们实际上不匹配。两个链接互不相同。您应在3rd /之后添加:,以使两个链接相同。

两条路由的方式不同,但是如果它们执行相同的操作,则应将问题报告给git上的express.js问题

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

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