Skip to content

ui-sref and $state.go() causes redundant state navigation under right circumstances #1569

@shank8

Description

@shank8

I have a ui-router site with the following states:

$stateProvider.state('order', {
            url: '/order/:serviceId',
            abstract:true,
            controller: 'OrderController'
        })
        .state('order.index', {
            url:'',
            controller: 'order-IndexController'
        })
        .state('order.settings', {
            url:'',
            controller: 'order-SettingsController'
        })

Where my two states do NOT have a url set, meaning they should only be reachable through interaction with the application. However the order.index state is automatically loaded by default because of the order in which I have defined the states.

I am noticing that trying to do a ui-sref="^.order.settings" or $state.go("^.order.settings") then ui-router first navigates to the order.settings state and then it immediately navigates to the order.index state (default state). I think this is happening because the url changing is causing a second navigation to occur and since the state.url == '' for both, it automatically defaults to the order.index state...

I tested this out by setting the {location: false} object in the $state.go('^order.settings', null, {location:false}). This caused the correct state to load (order.settings), but the url did not change. Therefore I think the url changing is triggering a second navigation.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions