"Dynamic" dynamic route segments


#1

I’m building an app where both the first portion and second portions of a route segment could be a number of different items, pulled from the database.

I obviously don’t want to hardcode a route for each one, but I’m unsure how to approach this. An example:

/georgia/atlanta
/georgia/marietta
/california/san-francisco
/california/bakersfield
/hawaii/honolulu
/hawaii/wahiawa

Would my router looks something like this?

App.Router.map(function() {
    this.resource('states', { path: '/:state_id' }, function(){
        this.resource('city', { path: ':city_id'});
    });
});

#2

Is this bit really easy and I’m just missing it? Or do I already have it right and just not realize it.


#3

That basically should work. The only thing I’d do is drop the leading slash in the /:state_id, it’ll be implied by being a root resource. Of course there’s more too it once you start adding in the data and linking between routes.