Asked By: Anonymous
I am trying to build an application with Ember.js, with routing, roles, login, logout, and all. My problem right now is that I cannot figure out how to deal with dynamic routing.
What I need, is to be able to use one route for sidebar navigation.
When the user logs in, he/she will get to the dashboard view. Say they click Post menu on the left, then they will see a posts view. I want to deal with these in the same route, something like /:module/
.
module: Ember.Route.extend({
route: '/admin/:module/',
doLogout: Ember.Route.transitionTo('login'),
connectOutlets: function (router) {
"use strict";
router.get('applicationController').connectOutlet('sidebar', 'sidebar');
router.get('applicationController').connectOutlet('toolbar', 'toolbar');
}
})
This is where I need a bit of help. How does the dynamic routing work exactly? Probably the only thing I found so far is @wycats’ gist on ROuting here, but I could not figure it out from there: https://gist.github.com/2728699
Solution
Answered By: Anonymous
Here is a stripped down piece of a dynamic routing I used:
myroute : Em.Route.extend({
route : '/myroute/:tid', //tid is same as index of Object
deserialize: function(router, params) {
return App.router.getPath('myController.content').objectAt(parseInt(params.tid));
//you can use some other parameters than tid and find the coresponding element
},
serialize: function(router, context) {
return {
tid: App.router.getPath('myController.content').indexOf(context)
}
},
connectOutlets: function(router, context) {
var currentController = router.get('currentController');
currentController.connectOutlet({
name : 'controllername',
outletName : 'outletname',
context: context
});
},
index: Em.Route.extend({
route : '/'
})
}),
Here is a Gist explaining Connect Outlets chack current source codes for latest updates https://gist.github.com/3606155