freedomflyer
freedomflyer

Reputation: 2551

Transition to a New URL State Without Reload

I'm using Angular UI Router 1.0.0-beta.1. Trying to transition from a state like /myroute/new to /myroute/5. Since the state with the id of 5 is very similar to the new state, I'd like to not reset important user state.

I've tried fairly well-documented approaches such as using the transitionTo method, like: $state.transitionTo(myRoute, params, {notify: false});, but this still refreshes the app.

How can I transition from the first url to the next silently?

Upvotes: 1

Views: 529

Answers (1)

Marc Stober
Marc Stober

Reputation: 10517

You can define your property as dynamic and then use $state.params to read it in the code.

Where you define you state:

$stateProvider.state({
    url: '/myroute/:id',
    params: {
        id: {
           dynamic: true
           ...

In your controller, inject $state and then you can read the params in your logic. You can also put an uiOnParamsChanged method on your controller to listen for changed parameters. This is in 1.0.0-beta.3. More reading: https://github.com/angular-ui/ui-router/issues/1758

Upvotes: 1

Related Questions