Angular-ui-具有多个父状态的路由器子状态

Angular-ui-router child state with multiple parent states

使用 Angular-ui-router,是否可以定义具有 多个父状态的子状态:

$stateProvider
    .state("parent1", {
        url: '/',
        templateUrl: 'parent1.html'
    })
    .state('parent2', {
        url: '/parent2',
        templateUrl: 'parent2.html'
    })

    //Make accessible from every state parent-state
    .state("child", {
        url: 'child',
//TODO  parents: ['parent1', 'parent2']
        onEnter: function() {
            //do something;
        }
    })

示例

Your Angular app has a directive that is used multiple times in different states in your app. The directive itself includes a link which redirects to a different state. Depending on where the directive is used, it should append its child-state to the current active parent-state.

为每个排列定义状态似乎并不正确,例如 state1.childstate2.child等等。需要有更好的方法。

这种层次结构会违反 DOM 树结构,根据定义,树结构不允许同一元素有多个父元素。

此外,它很容易出错(和令人头疼),并且在某些情况下很容易导致来自父状态的 multiple inheritance diamond problem, as child state do inherit

这听起来像是一个指令,而不是一个状态,将是您正在寻找的更好的解决方案。

编辑:

刚看到 closed issue on this, which is closed because he reached the same conclusion(指令是更好的方法)