johntlee / ch1-todo

0 stars 0 forks source link

App-Router.js: Odd Router Configuration #2

Open aubricus opened 10 years ago

aubricus commented 10 years ago

App-Router.js: Odd Router Configuration

Code in Question

appRoutes:{
        '*filter': 'filter'
    }

Description

It's possible you're not finished here; but you should be careful with a route that looks like *foo. This route will match any url and is typically how you configure a default route in Backbone.

Take another look at the Backbone Docs for Configuring Routes and make sure what you're doing there is intentional.

Just so you're aware, your default route should always be last in the configuration object. Backbone matches routes against the order they were created so you'll want Backbone to match against that route last.

If you were going to match a route like #filter/filter-type you might configure the route like:

'#filter/:filter-type': 'filter'

Remember that the value here is a function called on the Controller that will get the value passed in for :filter-type

filter: function(filterType): { ... }

Reference Link

https://github.com/tcl47/ch1-todo/blob/master/src/static/js/app/app-router.js#L6-L11

aubricus commented 10 years ago

You'll probably also want a default route:

'*index': 'index'