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:
/wallpapers/
list of wallpapers/wallpapers/:category_id/
list of wallpapers for specific category/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, because the router map automatically looks for the route/template/model/controller in specific directories. Any attempt to use the existing controller for both places causes it to work for one route only, or throw an error saying that the model was not found.
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
})
})
})
- Note that I prefer to keep the paths this way for reasons of preserving existing links.
- Note that the modal dialog can be reached from route 1 and route 2, but the modal itself has the same route regardless. Refreshing the page and losing state can cause the parent to switch. This is fine. I prefer the categorized list (2) to be the default parent.