Hello,
Let’s say I have an app about animes…
I want to be able to access the same anime with any of the following urls:
/a/foo/1
/a/foo
/a/1
so my router is defined as following:
// router.js
Router.map(function() {
this.resource('animes', { path: '/a/' }, function() {
this.route('add');
this.route('remove');
});
this.resource('anime', { path: '/a/:anime_id' });
this.resource('anime', { path: '/a/:slug/:anime_id' }, function() {
this.route('edit');
});
});
my anime route
looks like this:
// routes/anime.js
var AnimeRoute = Ember.Route.extend({
afterModel: function(anime, transition) {
// redirect to the url /m/foo/1
if(anime.get('slug') !== transition.params.anime.slug) {
this.replaceWith('anime', anime);
}
},
serialize: function(anime) {
return {
slug: anime.get("slug"),
anime_id: anime.get("id")
};
}
});
export default AnimeRoute;
My backend is configured to return the right data no matter if what was sent is an id or a slug.
There’s no problem in the case of urls in the form of /a/foo/1
and /a/1
, but in the case of the url: /a/foo
, the ember inspector shows that there’s an additional record {id: foo, title: undefined, slug: undefined, ...: undefined}
how to fix this?
EDIT: here’s a jsbin illustrating the problem: http://emberjs.jsbin.com/rasewowapocu/2