1

我配置了以下 routeProvider:

 angular.module('myModule').config ['$routeProvider', (provider) ->

   provider
  .when '',
     templateUrl: '/templates/dashboard.html'

  .when '/some_path/:some_param',
       templateUrl: '/templates/dashboard.html'

以及包装静态服务模板中的以下内容:

我也有适当定义的 templates/dashboard.html。

当我导航到该 url 时,会加载初始页面,但是 a#没有附加在 URL 上,当我尝试在控制器中使用$location.path('fooPath').

具体来说$location.path('fooPath'),将 URL 更改为current_dashboard_path/#/并重新加载,而我所期望的是将 URL 设置为:

current_dashboard_path/#/, 然后location('fooPath'), 将其更改为 current_dashboard_path/#/fooPath

一些额外的上下文:我想使用它,这样我就可以使用该$location服务来更改 url 而无需重新加载页面

#问题是,当填充 ng-view 时,如何强制 Angular 后置 a 。

4

1 回答 1

1

我的 routeProvider 中缺少以下行:

 .when '/',
      templateUrl: '/templates/dashboard.html'

此外,空白路线

 .when '',
     templateUrl: '/templates/dashboard.html'

需要删除

那么在不重新加载页面的情况下重写URL的方法在控制器中如下:

 lastRoute = route.current

 scope.$on('$locationChangeSuccess', (event)->
    route.current = lastRoute
 )
于 2013-04-11T00:11:03.363 回答