Backbone Router on any page change event

2019-09-16 15:53发布

问题:

I have the following routes:

routes: {
    ''                              : 'showSchedulePage',
    'Assignment/:assignmentTitle'   : 'showAssignment',
    ':pageType/:pageName'           : 'showPage'
},

Instead of the same code being fired in each of these functions, how can I fire a function when the URL is ANY one of the ones up top?

Thanks!

回答1:

Backbone plugin Routefilter allows you to define actions, which should be invoked before and after any route is executed. This allows you to extract common code from route handlers.