0

When my website is loaded I want to be redirected to a specific state. I do it with the following code.

angularRoutingApp.run(function ($rootScope, $state, $location, $transitions) {
    $transitions.onStart({}, trans = > {
        $state.go('menuNeurolengua', trans.targetState())
    });
}

But I throw this problem:

enter image description here

How can I solve that?

Kenji Mukai
  • 599
  • 4
  • 8
yavg
  • 2,761
  • 7
  • 45
  • 115
  • Normally you would just accomplish "redirected to a specific state on load" with a default state. This code will never work, since it is overriding *every transition, including the one that it is trying to use*, which will cause an endless loop. Is there some specific reason that a default state isn't usable in your case? – Claies Oct 06 '17 at 20:46
  • @Claies I know. I simply want to learn how to do this, then take the example and make my necessary validations. Can you help me with this please? – yavg Oct 06 '17 at 22:26
  • @Claies I want to get some way to detect when the user reloads the web page directly from the browser, or with f5. when I do, I want to redirect it to a default state to force it to do the internal navigation of the page. – yavg Oct 06 '17 at 22:27
  • check this: https://stackoverflow.com/questions/5004978/check-if-page-gets-reloaded-or-refreshed-in-javascript – pegla Oct 07 '17 at 07:31
  • @pegla it works. I will give you the best answer. post it please – yavg Oct 08 '17 at 04:21

1 Answers1

0

Since your only problem is finding out if user refreshed page or page was loaded, you could do something like this (make sure you inject $window):

if ($window.performance.navigation.type == 1) {
    console.info( "This page is reloaded" );
} else {
    console.info( "This page is not reloaded");
}

More explanation in this answer: Check if page gets reloaded or refreshed in Javascript

pegla
  • 1,866
  • 4
  • 17
  • 20