【问题标题】:AngularJS ui-router state not workingAngularJS ui-router 状态不起作用
【发布时间】:2017-10-24 16:45:39
【问题描述】:

当我使用这个状态名称 item.info 时,我无法访问页面:( 但是当我使用 itemInfo(not item.info) 之类的状态名称时,一切正常。如何修复它,有什么问题? UPD:没有错误显示。只有 url 更改而无需任何操作。 不工作:

.state('item', {
    url: '/items',
    template: '<items></items>',
}).state('item.info', {
    url: '/:itemId',
    template: '<item-info></item-info>',
    params: {
        itemId: null
    }
})

工作:

.state('item', {
  url: '/items',
  template: '<items></items>',
}).state('itemInfo', {
  url: '/item/:itemId',
  template: '<item-info></item-info>',
  params: {
    itemId: null
  }
})

【问题讨论】:

  • 它可能不起作用,因为 /:itemId 匹配 /items。您是否尝试过更改订单?
  • 什么意思?
  • 我试过这个.state('contacts', { url: '/contacts', }) .state('contacts.list', { url: '/list', template: '&lt;h1&gt;test&lt;/h1&gt;' }) 但它也没有成功,这很奇怪,因为它来自基本的角度教程
  • 这可能是您的 URL 的问题,如果您同时定义 /:itemId/items 后者可能不匹配,因为路由器总是选择第一个 - 我不知道 AngularJS路由器,但在 ExpressJS 例如这将是问题
  • 我试过你说的但也没成功

标签: javascript angularjs angular-ui-router


【解决方案1】:

试试这个:

 .state('item', {
    url: '/items',
    template: '<items></items>',
 })

 .state('item.info', {
    url: '^/:itemId',
    template: '<item-info></item-info>',
    params: {
      itemId: null
 }
})

来源: https://github.com/angular-ui/ui-router/wiki/URL-Routing

【讨论】:

  • 没有错误。唯一改变自己的是url。这就像状态没有看到模板或什么 idk
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-02-19
  • 2016-06-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-04-15
相关资源
最近更新 更多