angular-ui / ui-router

The de-facto solution to flexible routing with nested views in AngularJS
http://ui-router.github.io/
MIT License
13.54k stars 3k forks source link

Controller is reloaded on $state.go despite notify set to false. #3533

Closed dockinkong closed 6 years ago

dockinkong commented 7 years ago

Hello,

My version of UI-Router is: (1.5)

Bug Report

Current Behavior:

Controller is reloaded with $state.go('myApp', { }, { notify: false, reload: false, location: 'replace', inherit: false });

Expected Behavior:

Should the controller not reload with this options? I need to change the URL without reloading controller.

danidev commented 7 years ago

I have the same issue but I read that notify:false doesn't work anymore. I didn't find a solution to change the location without reloading the controller. Could somebody explain a new way to change the path of the page without reload the controller?

nkoterba commented 7 years ago

I've been struggling with this for over 2 days myself. I need to update the URL (as well as the browser history record) without actually re-loading the page/controllers.

I've tried just about every combination possible using both deprecated and "supported" options and methods and have yet to figure out a working solution.

Most of the information I've read says to use 'dynamic' on your state definition params (if that's what's changing or you want to change).

However, I've found that doesn't update the URL or add an entry to browser history.

Sharondio commented 7 years ago

Never good when you find yourself on a fresh issue thread after fighting with something for the better part of 2 days.

Sharondio commented 7 years ago

For those still following along, checkout the comments about the usage of notify: https://github.com/angular-ui/ui-router/issues/1758

shaggeh commented 6 years ago

Is there a workaround we can follow?

intergalacticspacehighway commented 6 years ago

$stateRegistry.register({name:state.name, url:'/'+state.stateUrlValue, template:element.content, controller:"stateController", reloadOnSearch:false });

I too had the same problem in spite adding parameters in $state.go, it was still reloading the controller Setting the value reloadOnSearch to false did the trick for me.

guillaumevincent commented 6 years ago

@shaggeh

add reloadOnSearch: false in your routes as a workaround:

.state({
  name: "names",
  url: "names",
  component: "Names",
  reloadOnSearch: false, 
})

In your controller $state.go("names", { param: 'newparams' });

maximilianschmid commented 6 years ago

relates to https://github.com/angular-ui/ui-router/issues/3650

maximilianschmid commented 6 years ago

think dynamic parameters is what replaced notify:false option

christopherthielen commented 6 years ago

People generally used notify: false to stay on the same state, manually fetch different data, and update the URL (usually changing a parameter value). However, notify: false was a bad idea because it introduced many edge cases and bugs that simply couldn't be reasoned about or worked around properly.

Dynamic parameters are intended to implement this most common use case, but in a way that isn't a horrible hack. Here is the current docs for dynamic parameter which describes what they do: https://ui-router.github.io/ng1/docs/latest/interfaces/params.paramdeclaration.html#dynamic

christopherthielen commented 6 years ago

here's a simple dynamic parameter example: https://stackblitz.com/edit/ui-router-angularjs-dynamic-parameter?file=app.js

it uses uiOnParamsChanged: https://ui-router.github.io/ng1/docs/latest/interfaces/ng1.ng1controller.html#uionparamschanged

dockinkong commented 6 years ago

With so much delay, thanks...