骨干路由的正则表达式 [英] Backbone routing regex

查看:90
本文介绍了骨干路由的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图让我的头围绕分拣此路由正则表达式的,所以:

Trying to get my head around sorting this routing regex out, so:

'quotes(/:action)': 'quotes',
'quotes/:id(/:params)': 'quotesEdit'

两个网址:

http://domain.com/#quotes/action=showModal
http://domain.com/#quotes/123

我的问题:

我怎样才能确保在URL中的 =行动上的第一个路由中的第二匹配,但不?而像报价网址/ 123 通过落到第二条路线?

How can I make sure that the URL with the action= matches on the first Route, but not the second? and for urls like quotes/123 to fall through to the second Route?

推荐答案

您的可以的过度骑 Backbone.history.loadUrl 你的特殊情况。从本质上讲,你会根据网址参数跳过匹配的路由......但似乎非常劈十岁上下。

You can make this work by over-riding Backbone.history.loadUrl with your special-cases. Essentially, you would be skipping matched routes based on the url parameters...but that seems awfully hack-ish.

这是选择是申报的论据单一路线和分支:

An option is to declare a single route and branch on the arguments:

'quotes(/:id)(/:params)': 'quotes'

quotes:function(id,params) {
  if (id && id.match(/^\d+$/)) { // if id is a number
    this.quotesEdit(id,params);
  }
  else {
    // your quotes logic
  }

除了上述情况,你可能要考虑改变你的路线了一下,你的问题是不再是一个问题。

Instead of the above, you may want to look into changing your routes a bit and your problem is longer an issue.

'quotes(/:action)'          : 'quotes',
'quotes/edit/:id(/:params)' : 'quotesEdit'

这篇关于骨干路由的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆