Anonymous
Anonymous

Reputation: 3414

Why does state.go with notify = false cause a future navigation to keep the current page's URL parameters?

There are some pages in my application where I'd like to update the URL with the current state so that the URL can be shared, but I don't want to reload the page because I can enter the new state without a full reload.

I've attempted to do this with $state.go(state, params, { notify: false }), which works... That is, until I navigate to some other page. When I navigate to the next page, the query parameters in my URL (for example, page number) are set on that page.

To be more concrete: I have a StateA where I call $state.go(StateA, params, {notify: false}). All is well. Then I navigate to StateB, but StateB now has parameters that I set on the previous $state.go call for StateA.

I defined an onEnter event for "StateB" and it shows that the state is being entered twice, once with the correct parameters and then again with the incorrect parameters from the previous $state.go call. If I comment out the $state.go with notify = false, the URL of course doesn't update but the future page transition works as expected.

Also note that this happens despite setting in the HTML template ui-sref-opts="{reload: true, inherit: false"} and my version of ui-router is 0.2.15.

Upvotes: 1

Views: 2634

Answers (1)

rrd
rrd

Reputation: 5957

I can't be sure since I haven't experienced it or tested it but if you look at this github.io page, you'll see a part on the notify option. It says this:

notify - {boolean=true}, If true will broadcast $stateChangeStart and $stateChangeSuccess events.

So setting it to false would not broadcast those events. This would in turn not cause a change in the url when you move from StateA to StateB.

Upvotes: 1

Related Questions