Backbone.js: URL路由中末尾的斜杠问题

22

我在我的应用程序中有URL路由,它们位于Router.js文件中:

'items': 'items',
'items/drafts': 'itemsDrafts',
'items/drafts/new': 'itemsDraftsNew',
...

但是在浏览器中,当我定义 items/drafts/new/ 时,它会给我返回404错误 :(

是否有一种方法可以使这些URL相同,而不需要复制粘贴所有路由并为它们添加尾随内容,例如:

'items': 'items',
'items/drafts': 'itemsDrafts',
'items/drafts/new': 'itemsDraftsNew',
'items/': 'items',
'items/drafts/': 'itemsDrafts',
'items/drafts/new/': 'itemsDraftsNew',
...

谢谢!

1个回答

44

9
感谢您抽出时间回答自己的问题,这对于互联网开发者非常体贴。 - Emile Bergeron
有没有人知道是否有一种方法可以将其设置为默认值?而不是在每个可能的路由中添加(/)。 - Silver Ringvee
1
url = url + '(/)'; // backbonejs 可选处理尾部斜杠 - Oleksii Kyslytsyn

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接