Angular UI-Router $ urlRouterProvider单击时不起作用

问题描述

先前的解决方案 在0.2.12-我们可以使用的版本之前$urlRouterProvider.when(),在文档中建议使用(小引用):

如何:设置认/索引子状态 … 如果您希望’parent.index’网址为非空,请使用$ urlRouterProvider在module.config中设置重定向

 $urlRouterProvider.when('/home', '/home/index');

因此,这是上述问答中显示解决方案:

var whenConfig = ['$urlRouterProvider', function($urlRouterProvider) {

    $urlRouterProvider
      .when('/app/list', ['$state', 'myService', function ($state, myService) {
            $state.go('app.list.detail', {id: myService.Params.id});
    }])
    .otherwise('/app');
}];
...
app.config(whenConfig) 

现在-我们不能。

UI路由器“ FIX”在 0.2.13 这是由于在版本0.2.13中提到的“ FIX” (我根本不确定)

Bug修复$状态: - ...... -从URL避免重新同步后.transitionTo(b267ecd3,关闭#1573)

这是urlRouter.js中添加的新代码

if (lastPushedUrl && $location.url() === lastPushedUrl)
 // this line stops the corrent .when to work
 return lastPushedUrl = undefined;

lastPushedUrl = undefined;

这段代码正在优化/修复其他问题 ……而且,关闭了.when()功能

解 如前所述,这个全新的插件提供了0.2.13+版本的方法。我们只需要听状态更改,如果状态为“ app.list”,我们可以使用一些ID来详细了解它。

var onChangeConfig = ['$rootScope', '$state',
 function ($rootScope, $state) {

  $rootScope.$on('$stateChangeStart', function (event, toState) {    
    if (toState.name === "app.list") { 
      event.preventDefault();
      $state.go('app.list.detail', {id: 2});
    }
  });

}]

解决方法

.when('/center','/center/question')在我的角度web应用程序。

当我'/center'在浏览器中键入内容时,它会重定向到'/center/question'我期望的位置,但是当我单击时<aui-sref="center" href="#/center"></a>,它不会重定向,而是停留在url上'/center'

我的控制台没有错误,我也不知道为什么。

当不再工作时 我在这里看到了一个类似的问题AngularUI-Router$urlRouterProvider。我尝试了答案,但它仍然对我不起作用。

这是我的coffeescript代码:

whenConfig = ['$urlRouterProvider',($urlRouterProvider) ->
  # default url config

  $urlRouterProvider
  .otherwise '/center'
  .when '/center','/center/question'
]

stateConfig = ['$stateProvider',($stateProvider) ->
  # nested url config

  capitalize = (s)->
    s[0].toUpperCase() + s[1..]

  mainConfig = ({
    name: name
    url: "/#{name}"
    templateUrl: "templates/#{name}.html"
    controller: "#{capitalize name}Ctrl"
  } for name in ['center','keywordList','keywordConfig','log','stat'])

  centerConfig = ({
    name: "center.#{name}"
    url: "/#{name}?page"
    templateUrl: "templates/center/#{name}.html"
    controller: "Center#{capitalize name}Ctrl"
  resolve:
    thead: (CenterService) ->
      CenterService.getThead @self.name
    data: (CenterService,$stateParams) ->
      CenterService.fetchItems @self.name,$stateParams.page
  } for name in ['question','answer','comment','article'])

  for singleConfig in mainConfig
    $stateProvider.state singleConfig

  for childConfig in centerConfig
    $stateProvider.state childConfig
]

app.config whenConfig
app.config stateConfig

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...