使用$ window.history.pushState会导致重定向

时间:2016-04-13 00:55:26

标签: angularjs

HTML:

<div class="mdl-card mdl-shadow--2dp mdl-card__video masonry-brick" ng-repeat="video in vm.videos" ng-click="vm.popupVideo(video)">
  <div class="mdl-card__media">
    <img ng-src="{{ video.poster }}" width="100%" height="100%" alt="">
  </div>
  <div class="mdl-card__supporting-text">
    {{ video.description }}
  </div>
  <div class="mdl-card__actions mdl-card--border">
    <i class="material-icons md-72 md-white">play_circle_filled</i>
  </div>
</div>

控制器:

vm.popupVideo = function (video) {
      var modalInstance = $uibModal.open({
        templateUrl: '/videoModal/videoModal.view.html',
        controller: 'videoModal',
        controllerAs: 'vm',
        size: 'md',
        resolve: {
          videoData: function () {
            return video;
          }
        }
      });

    };

弹出控制器:

function videoModal ($uibModalInstance, videoData, $sce, $location, $window, $timeout) {
    var vm = this;

    $window.history.pushState("abc", "Title", "/watch/skfhskf");
}

基本上,当我点击一个元素时,它会生成一个弹出窗口。而且我想在没有重定向的情况下更改地址栏网址,是不是$ window.history.pushState()应该做什么?但是当我在弹出控制器中使用它时,页面会重定向到/ watch / skfhskf。问题是什么?

我认为路由是造成问题的地方。这是我的路由代码:

function routeConfig ($routeProvider, $locationProvider) {
    $routeProvider
      .when('/', {
        templateUrl: 'home/home.view.html',
        controller: 'homeCtrl',
        controllerAs: 'vm'
      })
      .when('/watch/:watchid', {
        templateUrl: 'watch/watch.view.html',
        controller: 'watchCtrl',
        controllerAs: 'vm'
      })
      .otherwise({
        template: '<h1>Unmatched url</h1>'
      });

    $locationProvider.html5Mode(true);
  }

0 个答案:

没有答案