javascript - How do I disambiguate nested routes in ember.js? -
i have 2 resources both have same sub-resource:
class="lang-js prettyprint-override">app.router.map(function() { this.resource('post', function() { this.resource('comments', function() { this.route('new'); }); }); this.resource('product', function() { this.resource('comments', function() { this.route('new'); }); }); }); the problem ember router builds names of route objects out of current , parent routes, not out of whole hierarchy. thus, tries route both /posts/:id/comments/new , /products/:id/comments/new app.newcommentroute object. can prepare this?
this post adapted github issue.
i took james a. rosen's solution 1 step farther , worked charm. bit redundant, makes things much more intuitive downwards road:
app.router.map(function() { this.resource('post', function() { this.resource('post.comments', { path: '/comments' }, function() { this.route('new'); }); }); this.resource('product', function() { this.resource('product.comments', { path: '/comments' }, function() { this.route('new'); }); }); }); this allows utilize transitionto('product.comments.new') or app.register('route:product.comments.new', myroutehandler) expected.
if don't manually register route handler, ember, gracefully, in app.productcommentsnewroute
the downside redundancy of defining name of sub-resource same root name parent resource has.
javascript ember.js ember-router
No comments:
Post a Comment