KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
This is a follow-up from Understanding Ember routes . Master/detail views are great but I'm trying to have a a hierarchical URL route without nesting their templates. However, I still need access to the parent model for things like breadcrumb links and other references. So /users/1/posts should display a list of posts for user 1. And /users/1/posts/1 should display post 1 for user 1, but it shouldn't render inside the user template's {{outlet}} . Instead, it should completely replace the user template. However, I still need access to the current user in the post template so I can link back to the user, show the user's name, etc. First I tried something like this (Method #1): App.Router.map(function() { this.resource('user', { path: '/users/:user_id' }, function() { this.resource('posts', function() { this.resource('post', { path: '/:post_id' }); }); }); }); ... App.PostRoute = Ember.Route.extend({ model: function(params) { return App.Post.find(params.post_id); }, renderTemplate: function() { this.render('post', { into: 'application' }); } }); This replaced the the user template with the post one, as expected. But when I click the browser's back button the user template doesn't render again. Apparently the post view is destroyed but the parent view is not re-inserted. There are a few questions on here that mention this. I then got it to work with something like this (Method #2): App.Router.map(function() { this.resource('user', { path: '/users/:user_id' }, function() { this.resource('posts'); this.resource('post', { path: '/users/:user_id/posts' }, function() { this.resource('post.index', { path: '/:post_id' }); }); }); ...
Tags (comma-separated)
Save Edits
Cancel