使用 Angular 组件路由器时如何检测组件更改?

How can I detect the component change when using Angular component router?

现在我正在使用 ui-router 来处理授权:

$rootScope.$on('$stateChangeStart', function (event, toState, toParams, fromState, fromParams) {}

但是从 Angular1.5 开始,我如何使用 ngComponentRouter 来完成这项工作?

在新路由器中你有 Component Lifecycle Hooks:

angular.module('app', [])
  .controller('MyController', ['user', '$http', MyController]);

function MyController(user, $http) {
  this.user = user;
  this.$http = $http;
}

// Before switching to a new component, this hook runs for 
// each active component in the app. If any of them 
// return false, a rejected promise, or a promise that resolves to false,
// the navigation is cancelled.

MyController.prototype.canActivate = function() {
  return this.user.isAdmin;
};

//This hook fires just before the nagivation finishes.

MyController.prototype.activate = function() {
  return this.bigFiles = this.$http.downloadBigFiles();
};