骨干路由:包含一个只有两个允许值的变量?

时间:2012-02-22 16:46:02

标签: javascript backbone.js

我想编写一个带有变量的骨干路径,该变量只能带两个值。在下面的示例中,我希望路由从/ca/.../us/...开始路由到handleByCountry。

我需要使用正则表达式吗?这是当前的代码:

var AppRouter = Backbone.Router.extend({
      routes: {
          ":country/:str": "handleByCountry", // country should only be 'ca' or 'us'
      },
      handleByCountry: function(country, str){
          // handle 'ca' and 'us' values differently
      },
  });

1 个答案:

答案 0 :(得分:0)

你拥有它的方式应该可以正常工作。如果handleByCountry不等于countryca,您只需在us中向用户显示错误消息。

相关问题