Backbone.js:url路由末尾的斜杠

时间:2013-07-10 11:55:02

标签: javascript url backbone.js router

我的应用Router.js中有网址路径:

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

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

有没有办法让这些网址相同而不复制粘贴所有路线并添加尾随,如:

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

谢谢!

1 个答案:

答案 0 :(得分:44)

我的解决方案:'url(/)': 'urlFunc'

() - 表示可选(另请查看此处 - https://stackoverflow.com/a/14329976/2117550