Angular child state causing url change

时间:2017-07-12 08:05:55

标签: angularjs angular-ui-router

I have these states defined (after defining an abstract state site):

            .state('catalog', {
                parent: 'site',
                url: '/catalog?salesorg',
                template: '<catalog></catalog>'
            })
            .state('product', {
                parent: 'catalog',
                url: '/product/:id',
                template: '<product-details></product-details>'
            })

I try to go to the product state with this:

$state.go('product', { id: materialNumber });

Which is fired by:

<a ng-click="vm.goToProductDetails(product.materialNumber)">Product</a>

The page does not change though the URL does:

/#/catalog/product/000000000000123805

I am trying to make the product state a child of catalog state so that it can inherit the scope of catalog, but I don't want to have the URL include /catalog before /product as that would break the current URL scheme.

1 个答案:

答案 0 :(得分:0)

我们应该调整:

  • 目录状态,具有其子项目标
  • 产品状态网址定义,跳过父部分

example

    .state('catalog', {
      parent: 'site',
      url: '/catalog?salesorg',
      template: '<catalog></catalog><div ui-view="" ></div>'
    })
    .state('product', {
      parent: 'catalog',
      url: '^/product/:id',
      template: '<product-details></product-details>'
    })

检查完整内容here