Search code examples
javascriptbackbone.js

possible to do params in backbone routes


I was looking at routes in backbone and I was wondering if I can do the following:

routes: {
    '': 'posts',
    'posts?page=:page': 'posts'
}

This would allow me to do just a plain index of posts and also add pagination to that index of posts.

Is this something that is ok or is there a better way to do this?


Solution

  • Is using a query parameter a requirement? If not, you can use the Router's param functionality:

    routes: {
        '': 'posts',
        "page/:page": "posts"   // #page/N
    }