Alon
Alon

Reputation: 3906

Backbone routes and filtering - a better way

I'm creating an app which receive a collection of data and display it on the page

Since I would like to filter it by location, dates, prices, and rating I had to create the next routes:

":location": "func1"
":location/dates/:dates": "func2"
":location/dates/:dates/prices/:prices": "func3"
":location/dates/:dates/prices/:prices/ratings/:ratings": "func4"
":location/dates/:dates/ratings/:ratings": "func5"
":location/prices/:prices": "func6"
":location/prices/:prices/ratings/:ratings": "func7"
":location/ratings/:ratings": "func8"

You can see there are duplicates here and I would to avoid it and be able to catch all the filters in the url

How can it be achieved in a better way so I won't need to duplicate routes according to all the possibilities?

Upvotes: 1

Views: 51

Answers (1)

Puigcerber
Puigcerber

Reputation: 10104

You could probably reduce it to just one route using optional parameters:

":location(/dates/:dates)(/prices/:prices)(/ratings/:ratings)": "func1"

Upvotes: 1

Related Questions