15

For example, I want this change in navigation to reload the state:

  • #/detail/1
  • #/detail/2

But I do not want this navigation to reload the state:

  • #/detail/1?search=blah
  • #/detail/1?search=huzzah

According to the ui-router documentation, setting reloadOnSearch: false should accomplish this, but try the plunk below. When reloadOnSearch === false, changing the path parameter doesn't reload the state even though the documentation says it should.

Plunkr: http://run.plnkr.co/ZPy9uabYlkMilwdS/#/param

1
  • DId you ever find a solution to do what you stated above? I'm needing the same thing. Commented Jun 9, 2015 at 15:27

2 Answers 2

35
+50

I've created a plunker, demonstrating that ui-router feature reloadOnSearch is working as documented here:

reloadOnSearch:

Boolean (default true). If false will not retrigger the same state just because a search/query parameter has changed. Useful for when you'd like to modify $location.search() without triggering a reload.

So, what this says, that if we do have state like this

.state('index.detail', {
      url: '/detail/:id',
      reloadOnSearch : false,
      ...
    })

navigating to the

  • ui-sref="index.detail({id:1})"

will load this state, while navigating to

  • ui-sref="index.detail({id:any-other-id})"

will do nothing. But! If we would introduce new (e.g. sibling) state defined like this:

.state('index.other', {
      url: '/other/:id',
      reloadOnSearch : false,
      ...
    })

navigating to below sequence will always re-trigger state reload, not because the param change, but because the state change

  1. <a href="#/index/detail/1" ...
  2. <a href="#/index/other/1" ... // will relaod
  3. <a href="#/index/detail/2" ... // because the state
  4. <a href="#/index/other/2" ... // is changing

See that all in action here...

Sign up to request clarification or add additional context in comments.

10 Comments

Thanks, but this doesn't answer my question. "If false will not retrigger the same state just because a search/query parameter has changed." "search/query parameter" refers to $location.search(), i.e. everything after the question mark. I want to be able to change what's before the question mark and reload the state.
This is missunderstanding of the terms. 1) search/query parameters are parts of the url mapped as params (e.g. stateName/paramValue/stateName?param1=value1&param2=value2). Parts mapped as state-name identificators are the rest. So what is the reloadOnSearch = false about? do not trigger state reload, if params parts of the url are changed. But if the state itself is changed... it will reidrect. Is it a bit more clear?
From perspective of the ui-router, url represents unique state definition. It could be one or many/nested states with many params. Some could be even in a format of a github.com/angular-ui/ui-router/wiki/… - query params. But at the end, this url is converted into 1) states and 2) params. Nothing more. And reloadOnSearch=false means: any param of current state has changed == do not reload. That exactly is what the docum. says, and that's what my plunker shows 1:1. But I just tried to explain, do not get me wrong... I accept that you see that differently..
@MattYork in your OP you are changing the parts after the hash, and have reloadOnSearch set to false - which is designed to ignore changes in the parts after the hash. The issue is very simple to understand. The documentation may be ambiguous, but RadimKöhler is simply stating true facts about how it works.
@JoshRibakoff there's two different types of url parameters: path and search (aka query). reloadOnSearch is intended to only apply to search parameters, not path parameters. See this issue: github.com/angular-ui/ui-router/issues/1191
|
2

This is a bug in UI-Router that was fixed in release 0.2.15:

https://github.com/angular-ui/ui-router/releases

Upgrading to the latest will fix the issue

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.