问题
In some case I got an issue with the routing url. Here's my router :
contacts: Em.Route.extend({
route: '/contacts',
index: Em.Route.extend({
route: '/',
connectOutlets: function(router, context) {
App.contactsController.populate()
var appController = router.get('applicationController');
appController.connectOutlet('contactsList');
}
}),
show: Em.Route.extend({
route: '/:contactid',
connectOutlets: function(router, context) {
alert('show contact');
}
}),
doShowContact: function(router, event){
router.transitionTo('show', {contactid: event.context.id});
}
}),
When I enter inside doShowContact, if I specify 'contactid' as context and '/:contactid' as route inside 'show', I'll get for example '/contacts/3' in the browser url, everything is ok.
However in doShowContact, if I specify 'contact_id' rather than 'contactid' as context and '/:contact_id' rather than '/:contactid' as route. I'll get '/contacts/undefined' in the browser url.
Is there a way to explain it ? Thanks!
回答1:
You should simply pass the contact instance, not forge an object with contactid
property:
doShowContact: function(router, event) {
var contact = event.context;
router.transitionTo('show', contact);
}
You should also specify the modelClass
property in your route:
show: Em.Route.extend({
route: '/:contact_id',
modelClass: App.Contact,
// ...
})
来源:https://stackoverflow.com/questions/11684615/emberjs-route-with-args-fail-in-some-case