bizibiz17
bizibiz17

Reputation: 31

angular ui-router change url with no controller reload

I'm working on a project with angular 1.6.x and ui-router 1.0.x

I want to change the browser url without reloading states, to do so I tried this :

   $state.transitionTo($state.$current.name, {param1: "value"}, {
                location: true,
                inherit: true,
                relative: $state.$current,
                reload: false,
                //Seems to be deprecated...
                notify: false
            });

I just want to change the param1 value in url, but transitionTo reloads my current state and so destroy and re-create my controller.

I previously worked with ui-router 0.x and the notify parameter worked for that.

How can I do this with ui-router 1.0.x ?

Thank you !

Upvotes: 0

Views: 1582

Answers (2)

bizibiz17
bizibiz17

Reputation: 31

The fact is I was not in the right direction !

To do so I have to define the parameter as a dynamic :

https://ui-router.github.io/ng1/docs/latest/interfaces/params.paramdeclaration.html#dynamic

Thanks to @Anber

Upvotes: 1

Fritz Herbers
Fritz Herbers

Reputation: 104

I think it is a bug (using ui-router 1.0.3).

Definition:

.state('app.order', {
        url: '/order/:id',
        params: { 
            id: { value: null }    // id is optional
        },
        .....

Tried all variants:

 some_id can either be an int or null

 $state.go('.', {
            id: some_id
        }, { location: true });

 $state.go('.', {
            id: some_id
        }, { location: "replace" });

 $state.go('.', {
            id: some_id
        }, { location: true, reload: false });

 $state.go('.', {
            id: some_id
        }, { location: "replace", reload: false });

Upvotes: 0

Related Questions