mardi 10 janvier 2017

Ember 2 - Transition to route through component

I am trying to make a pagination component for ember 2 app. Since it is a general purpose pagination component, I wanted to use it on many different routes. Because of that I need to somehow (in my mind) provide a name of my route for pagination links to work.

I can pass in my route name (string) to the component easily: . And inside of component:

It works well for going to pages like: << First, < Previous, Next > , Last >>.

But I also wanted to have a select box with options pointing to all the pages, where if user selects a page, I can transition into that route with queryParams similar to this: myRoute?page=selectedPage. All the tutorials for ember say that transitioning within the component is a no-no.

But how do I do it instead, given that I want my pagination to be generic and I don't want to have action within every single route that deals with pagination and provide same exact transitioning?

So far I found that I can inject the '-routing' into the component, which can work for transitioning within the component, but it also doesn't quiet work for some reason. Plus people say that it is private and unreliable. I also tried making a Route Mixin with action so I can simply sendAction from the component with the selectedPage, but I don't know how to get the router (in order to call router.transitionTo) within my Mixin.




Aucun commentaire:

Enregistrer un commentaire