Hi,
I want to redirect to a route “recipe/2” for example from a component.
In order to do this I injected the router router: Ember.inject.service("-routing")
in my component and then I’ve tried to redirect on click using this
this.get("router").transitionTo("/recipe/" + clicked.dataset.id);
(Assertion Failed: The route /recipe/2 was not found)
I also tried using
this.get("router").transitionTo("/recipe/", clicked.dataset.id);
(ember.debug.js:49883 Uncaught TypeError: objects.pop is not a function(…))
and this.get("router").transitionTo("/recipe/" , this.get("store").findRecord("recipe", clicked.dataset.id));
(ember.debug.js:49747 Uncaught TypeError: this.contexts.slice is not a function)
How should I do a redirect from component and why is not documented this very usual case? I mean, you have a component that searches for recipes for example and when the user hit click on one from search results you want to get him to that recipe. Is a usual case not some exception.
I think that approach would not be very efficien. As components are suppose to work independently.
Rather when an event happens and you want to transition to another route, use sendAction in the component with needed arrguments and let route handle the transition. You can also use closure action instead of sendAction.