Skip to content

Deep Linking and State Transitions #200

Closed
@gwright

Description

@gwright

I'm trying to better understand how to effectively organize my code around the state transitions model presented by ui-router. I'm also new to Angular so please feel free to point out my mistakes.

It seems as though there are two general sources of state transitions:

  • explicit calls to transitionTo(), often triggered by controller functions due to UI interaction
  • implicit calls via changes to the URL either via landing on a deep link or end-user edits of the URL

By default, $stateProvider configuration takes care of updating the URL and changing the view to match the new state but any other application logic has to be handled separately.

It would make sense to put all that logic in the controller but I'm having a hard time understanding how to arrange for those implicit state transitions to trigger a controller function.

onEnter and onExit would seem to be the obvious 'hooks' but I'm not sure how to provide the correct $scope to those callbacks, they aren't injectable functions.

So what is the recommended way to react to state transitions triggered by deep links and/or URL edits by the user? Should I be putting all that logic in the controller or should it be somewhere else?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions