2

I'm using UI-Router to manage the states of my application, and I have query params where I save some data about the application.

I'm using ui-sref no navigate to another state, but this removes the query params from the URL. Is there any way to change the state of the application without removing the query params?

Radim Köhler
  • 122,561
  • 47
  • 239
  • 335
Ephi Gabay
  • 938
  • 7
  • 27

1 Answers1

3

There is an option {location : false} - check the doc:

go(to, params, options)

... Options object. The options are:

  • location - {boolean=true|string=} - If true will update the url in the location bar, if false will not. If string, must be "replace", which will update url and also replace last history record.
  • inherit - {boolean=true}, If true will inherit url parameters from current url.
  • relative - {object=$state.$current}, When transitioning with relative path (e.g '^'), defines which state to be relative from.
  • notify - {boolean=true}, If true will broadcast $stateChangeStart and $stateChangeSuccess events.
  • reload (v0.2.5) - {boolean=false}, If true will force transition even if the state or params have not changed, aka a reload of the same state. It differs from reloadOnSearch because you'd use this when you want to force a reload when everything is the same, including search params.

But I would rather keep such parameters as part of target state url:

Community
  • 1
  • 1
Radim Köhler
  • 122,561
  • 47
  • 239
  • 335
  • Hey, thanks for the comment. But I do want to url to be replaced, but just just the path part, not the query params – Ephi Gabay Oct 13 '15 at 08:55
  • As I said, there is solution "keep such parameters as part of target state"... so I would suggest to extend target state, and pass these params as well. That would be the native UI-Router solution... Does it help? It could even be driven by state inheritance, so these params are defined by parent and child just profit from it... – Radim Köhler Oct 13 '15 at 08:57
  • Thanks, I ended up passing the params inside the ui-sref (`ui-sref="secondPage({param1: value1})"`) I just thought maybe there is an easier way just to leave the query params as they are. – Ephi Gabay Oct 13 '15 at 09:12