0

I current have a link as below in xyz page i.e. #/xyz:

<a href="#/abc/def?zqp=2&bqp=1">Random Text</a>

Upon clicking this I go to below url first

#/abc/def?zqp=2&bqp=1

And then the url changes to below url cause I believe ember-js takes in query params in alphbetical order

#/abc/def?bqp=1&zqp=2

Can you observe that order of query params has changed from

zqp=2&bqp=1 to bqp=1&zqp=2

I believe this is because ember js takes the query param as per alphabetical order

Now in bqp=1&zqp=2 when I press back I dont go to xyz instead I go zqp=2&bqp=1 with an error saying undefined route.

How to prevent this apart from re-ordering the query-params?

Note: I have not used ember link-to but have the href of link tag set directly. Cannot change this to link-to btw.

wallop
  • 2,510
  • 1
  • 22
  • 39
  • Have you defined your query params in controller? Following your logics any word would be alphabetically ordered :D? – kristjan reinhold May 24 '16 at 18:51
  • yep defined in controller, I didn get you "any word would be alphabetically ordered"? – wallop May 24 '16 at 19:13
  • 2
    Query params are order-independent. Nothing in your APIs, or in Ember, depends on their order. A different order of query params could not cause an undefined route error. –  May 24 '16 at 19:43
  • you could try it in your app, let me see if i can create a JSBin. Once I rectify the order it works just fine. – wallop May 24 '16 at 19:54
  • What does your router look like for `abc/def`? It shouldn't have any segments in there. Are you putting your query parameters in the controller [like this](https://guides.emberjs.com/v2.3.0/routing/query-params/)? – Paul Oliver May 25 '16 at 00:21
  • @wallop if i used for instace "?car=1" => ?acr=1 – kristjan reinhold May 25 '16 at 05:45
  • @PaulOliver I have been working on ember for quite sometime now so yes the declaration of queryParams and more are as they should be – wallop May 25 '16 at 17:53
  • @torazaburo it does not cause undefined route error when it is entered but while pressing back it does. I am trying to create an example. If you can run that locally you can observe the same – wallop May 25 '16 at 17:54
  • `bpq` changes to `bqp`? –  May 25 '16 at 18:02
  • @torazaburo sorry my bad, I corrected, I meant bqp=1&zqp=2 changes to zqp=2&bqp=1. – wallop May 25 '16 at 18:59
  • Is xyz not an ember.js page? Is that why you can't use link-to? – Gaurav May 25 '16 at 19:04
  • yep it is, its a dynamic for-each link I am creating in a component so this.transitionTo or link-to is not possible. I know i can still send to parent controller and do but that is not optimal. Anyway the question why this is happening since it should not – wallop May 26 '16 at 00:05

0 Answers0