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 に移動すると、最初のページが読み込まれますが、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 に後置を強制するにはどうすればよいかということです。

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 に答える