ui路由器后退按钮问题

时间:2017-07-05 16:42:27

标签: javascript angularjs angular-ui-router url-routing frontend

我正在使用ui-router版本0.3.2和角度1.5的web应用程序。我有后退按钮的问题,当我点击后退按钮时,网址更新到适当的状态网址,但不会重新加载/呈现页面。新状态的控制器(更新的URL)不会被执行。以下是我的状态配置

$stateProvider
.state('home', {
  url: '/',
  reloadOnSearch: false,
  templateUrl: 'homePage.html',
  controller:'homeController'
})
.state('home.overView', {
  url:'overView',
  reloadOnSearch: false,
  views: {
    ovSB: {
      templateUrl: 'searchParameterBarTemplate.html',
      controller: 'searchParameterBarController'
    }
  }
})
.state('home.overView.result', {
  url:'/:docType?abc&xyz&type&user&temp1&temp2',
  abstract: true,
  reloadOnSearch: false,
  templateUrl: 'resultViewTemplate.html',
  controller : 'resultPanelController'
})
.state('home.overView.result.dashboard', {
  url:'',
  reloadOnSearch: false,
  views: {
    'chart': {
      templateUrl: 'chart-template.html',
      controller: 'chart-Controller'
    },
    'oVGrid': {
      templateUrl: 'ov-grid-template.html',
      controller: 'ov-grid-controller'
    },
    'filterGrid': {
      templateUrl: 'filter-stats-template.html',
      controller: 'filter-stats-controller'
    }
  }
})
.state('home.delta',{
  reloadOnSearch: false,
  url:'Delta',

  views:{
    pcSB:{
      templateUrl: 'search-parameterbar-delta-template.html',
      controller : 'search-parameterBar-delta-controller'
    }
  }
})
.state('home.delta.result',{
  url:'/:docType?xyz_1&abc_1&xyz_2&abc_2',

  reloadOnSearch: false,
  templateUrl: 'delta-template.html',
  controller : 'delta-controller'
})
.state('home.details', {
  url: 'details',

  views: {
    detailsSB: {
      templateUrl: 'search-paramBar-details-template.html',
      controller: 'search-paramBar-details-controller'
    }
  }
})
.state('home.details.result', {
  url: '/:documentType?abc&xyz&user&temp1&temp2',
  abstract: true,
  templateUrl: 'details-view-template.html',
  controller: 'details-view-controller'
})
.state('home.details.result.dashboard',{
  url:'',
  views:{
    perGraph : {
      controller :'per-graph-controller',
      templateUrl: 'per-graph-template.html'
    },
    detailsGrid: {
      controller: 'details-grid-controller',
      templateUrl: 'details-grid-controller-template.html'
    }
  }
});

例如,如果我从home.overview.result.dashboard导航(url - &gt; localhost:12345 / overview / doctype?abc&amp; xyz&amp; user&amp; temp1&amp; temp2 < / strong>)状态为home.details.result.dashboard状态,网址为 localhost:12345 / details / doctype?abc&amp; xyz&amp; user&amp; temp1&amp; temp2 并点击后退按钮,网址更新为 localhost:12345 / overview / doctype?abc&amp; xyz&amp; user&amp; temp1&amp; temp2 但不会重新加载/呈现网页。

我相信我可以使用此solution并触发重新加载,但我正在寻找一种比ue路由器更好的解决方案。有什么我缺少状态配置/做错了吗?任何与此有关的帮助将受到高度赞赏。 谢谢

1 个答案:

答案 0 :(得分:1)

它将触发$ stateChangeStart事件。使用location指令来解决它。请参阅以下代码段

$rootScope.$on('$routeChangeStart', function (event,next) { 
    $location.path(next.$$route.originalPath);
});

这可以解决您的问题。但它不是完美的解决方案