Ruby on rails 3.2 具有自定义默认路由的主干路由器

Ruby on rails 3.2 具有自定义默认路由的主干路由器,ruby-on-rails-3.2,backbone-routing,Ruby On Rails 3.2,Backbone Routing,我想在视图上启动一个主干应用程序,它已经由Rails呈现 这是我的路由器代码 class App.Routers.Dashboard extends Backbone.Router routes: '': 'index' 'locations/:id': 'showLocation' index: -> alert "Dashboard page" initialize: -> @route(/\/?/, 'index', @index);

我想在视图上启动一个主干应用程序,它已经由Rails呈现

这是我的路由器代码

class App.Routers.Dashboard extends Backbone.Router
 routes:
  '': 'index'
  'locations/:id': 'showLocation'

  index: ->
     alert "Dashboard page"

  initialize: ->
    @route(/\/?/, 'index', @index);  
然后在渲染视图中,我启动应用程序

$ ->
 App.appRouter = new App.Routers.Dashboard()
 Backbone.history.start
  pushState: true
  root: "/dashboard"
但是,如果我打开页面

http://localhost:3000/dashboard
路由器未进入“索引”状态


我错过了什么吗?

只有当URL位于根目录时,默认路由为
'
才会匹配

在您的示例中,“索引状态”将仅使用
url调用http://localhost:3000/

建议使用“splat”路由
“*路径”:“索引”
。因为此路由实际上表示匹配任何内容,所以您需要确保它是定义的最后一个路由