Skip to content

Bug in duplicate state name checking when using 'parent' definitions #368

Closed
@marklagendijk

Description

@marklagendijk

Currently there are 3 ways of defining states:

  1. Using 'dot notation'. For example name: 'contacts.list'
  2. Using the parent property with the parent name as string. For example: parent: 'contacts'
  3. Using the parent property with the parent object. For example parent: contacts (where 'contacts' is an stateObject)

What you would expect is that method 2 and 3 would resolve the name to the 'dot notation'. However, currently this doesn't seem to happen. Because of this the code which checks for duplicate stateNames wrongfully throws errors when 2 children of different parents have the same name.
For example:

$stateProvider
    .state({
        name: 'contacts',
        templateUrl: 'contacts.html'
    })
    .state({
        name: 'list',
        parent: 'contacts',
        templateUrl: 'contacts.list.html'
    })
    .state({
        name: 'products',
        templateUrl: 'products.html'
    })
    .state({
        name: 'list',
        parent: 'products',
        templateUrl: 'products.list.html'
    });

Or object notation:

var contacts = {
    name: 'contacts',
    templateUrl: 'contacts.html'
};
var contactsList = {
    name: 'list',
    parent: contacts,
    templateUrl: 'contacts.list.html'
};
var products = {
    name: 'products',
    templateUrl: 'products.html'
};
var productsList = {
    name: 'list',
    parent: products,
    templateUrl: 'products.list.html'
};

$stateProvider
    .state(contacts)
    .state(contactsList)
    .state(products)
    .state(productsList)

Both throw an error:

Error: [$injector:modulerr] Failed to instantiate module `APP_MODULE` due to: State 'list'' is already defined

While defining this example using method 1 does work:

$stateProvider
    .state({
        name: 'contacts',
        templateUrl: 'contacts.html'
    })
    .state({
        name: 'contacts.list',
        templateUrl: 'contacts.list.html'
    })
    .state({
        name: 'products',
        templateUrl: 'products.html'
    })
    .state({
        name: 'products.list',
        templateUrl: 'products.list.html'
    });

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions