Reputation: 2276
I'm using Ember 3, and I am having an issue using the Router service with dynamic segments. In my component, I use the Router Service to transitionTo
a child route on a click, but I get this error:
Error: More context objects were passed than there are dynamic segments for the route: data.images.image
This is in the component js, where I use transitionTo and pass one parameter for the one dynamic segment:
router: service(),
actions: {
navToSubpage() {
// this.image is a single Ember Data record/object
this.router.transitionTo('data.images.image', this.image)
}
},
This is from my router, which has nested routes with one dynamic segment:
Router.map(function() {
this.route('data', function() {
this.route('images', function() {
this.route('image', {path: '/image_id'});
});
});
});
What am I doing wrong? The error doesn't make sense to me in this case.
Upvotes: 1
Views: 931
Reputation: 2276
I was missing a :
before image_id
in my Router. The router therefore did not recognize image_id
as a dynamic segment, so my transitionTo
was interpreted as having too many parameters (1 instead of 0). It had nothing to do with the Router Service.
This is the corrected Router:
Router.map(function() {
this.route('data', function() {
this.route('images', function() {
this.route('image', {path: '/:image_id'});
});
});
});
Upvotes: 6