Matt H
Matt H

Reputation: 409

angular ui-router - how to detect direct navigation to a state

I'm using $transitions to detect state changes and take some action based on the difference between some data defined in the 'from' and 'to' states. This is working great for me, but this code is not hit when the user navigates directly to a state via url. For example, browsing to mysite/search does not trigger this, but navigating within the site from the home page to the search page triggers this.

Is there any way to detect that the state was directly navigated to? That would allow me to execute the logic that I need to.

$transitions.onSuccess({}, trans => {
  myFunc(trans.$from().data, trans.$to().data);
  return true;
});

Upvotes: 0

Views: 193

Answers (1)

Matt H
Matt H

Reputation: 409

My problem was that I didn't register the transaction early enough; it was in a service that wasn't loaded until after transitions were handled for the initial launch of the app.

Upvotes: 1

Related Questions