Default Routes in a Backbone.js controller?

前端 未结 2 2039
不知归路
不知归路 2021-01-31 01:55

I want to set a default route for my backbone.js controller. Currently I do it like so:

class DealSearchController extends Backbone.Controller
    routes:
               


        
2条回答
  •  孤街浪徒
    2021-01-31 02:53

    Try adding this additional route as the last route in your controller:

    '*path':  'defaultRoute'
    

    and then handle it like this:

    defaultRoute: function(path) {
        this.showListView();
    }
    

    This assumes the list route is your preferred default. This should work since Backbone.js will match the routes in order, but will always match the 'splat' route.

提交回复
热议问题