2

I found a solution when I can chage url with page reloading in AngularJS:

$window.location = "new_url";
$window.location.reload();

It has a by-effect - $window.location = "new_url" changes state/route immidiately and you can discover loaded new controller's template and even discover network connections at controler's initialization, only then $window.location.reload() code is executed that reloads the page.
I trided several ways like described here https://stackoverflow.com/a/26853786/551744

$state.go("state name", "state params", { reload: true });

but does not work for me, it does not reload the page.
This code does not work too:

$state.go("state name", "state params", { notify: false });
$state.reload();

I use this way, described here https://stackoverflow.com/a/25649813/551744:

$state.go("state name", "state params", { notify: false });
setTimeout(function() {
   $window.location.reload();
}, 500);

bahaviour very close to needed (after url is changed state does not load new controller and template): $state.go("state name", "state params", { notify: false }); changes only url and $window.location.reload(); realods page with new url. But this way has by-effect: I need use setTimeout to wait when url will be changed. I don't know why but it doesn't happen immidiately. I tried set 0ms, 50ms, 100ms, but sometimes url changes not fast enough and page realods with previous url.

How can I overcome:

  • "setTimeout code" problem;
  • or detect event when url is changed to force page reloading (it can be a problem because code contains { notify: false });
  • or other solution?

1 Answer 1

0

Maybe you need to watch for the state change event:

https://github.com/angular-ui/ui-router/wiki#state-change-events

Then you can trigger your code to initialise in the controller.

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

3 Comments

{ notify: false } make url to change but it doesn't rise events $stateChangeStart or $stateChangeSuccess, but { notify: true} (as default) - does. But I can't use { notify: true} because it is the same as first sample
Is there a reason you are using $state.go instead of $location.path? Maybe I need to see some more code to fully understand what you are trying to do.
I need change url/route/page with page load. I can use $window.location = "new_url"; $window.location.reload(); or any other ways but they have a by-effect described in question. So i need have an ability to change url/page with reload but without a by-effect of redundant actions

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.