mardi 26 septembre 2017

How to re-use an ember route in two different routes?

My router has paths setup for listing wallpapers. The index shows a list of wallpapers. There is also a categorized list of wallpapers. And lastly, there's a page for viewing a specific wallpaper.

The paths are setup like this:

  1. /wallpapers/ list of wallpapers
  2. /wallpapers/:category_id/ list of wallpapers for specific category
  3. /wallpapers/:category_id/:wallpaper_id/ Single wallpaper page

Entries in both 1 and 2 show 3 after a click.

Now I want 3 to be a modal that pops up with the previous route in the background. I can get this to work using either 1 or 2 as parent. But if I want to do this for both, I need to completely duplicate the route, controller, template and model for 3. Any attempt to use the existing controller for both places causes it to work for one route only.

How can I use the same route/controller/template/model combo for the modal to be used in both 1 and 2?

Router.map(function() {
    this.route('wallpapers', function() {
        this.route('index', { path: '/' }, function() {                         // All wallpapers
            this.route('wallpaper', { path: ':category_id/:wallpaper_id' })     // Modal dialog
        })
        this.route('category', { path: ':category_id' }, function() {           // Categorized wallpapers
            this.route('wallpaper', { path: ':wallpaper_id' })                  // Modal dialog
        })
        this.route('wallpaper', { path: ':category_id/:wallpaper_id' })         // Single wallpaper
    })
})




Aucun commentaire:

Enregistrer un commentaire