mardi 25 août 2015

Proper Use of Nested Routes

I was trying to get the following working:

Router.map(function() {
    this.route('games', function() {
        this.route('game', {path: '/:game_id'}, function() {});
    });
});

I had a directory structure like so:

templates
  - games
    - index.hbs
    - game.hbs

Clearly, this wasn't working. I couldn't really figure out how to get game.hbs to render. After doing some research, I stumbled on an article from 2013 and that led me to this solution:

Router.map(function() {
    this.route('games', function() {});
    this.route('game', {path: 'games/:game_id'}, function() {});
});

templates
  - games
    - index.hbs
  - game
    - index.hbs

Note that I had to include the empty function() { } in both routes to get the subdirectory structure to work.

I'm using Ember 1.13.7 and I'm wondering if this is still the correct approach. Or is there a way I can nest the game route without having anything additional on the path to get it to work?




Aucun commentaire:

Enregistrer un commentaire