text: export function insertView(views, view, direction) {
      if (direction === 'root') {
          return setRoot(views, view);
      }
      else if (direction === 'forward') {
          return setForward(views, view);
      }
      else {
          return setBack(views, view);
      }
  }
  function setRoot(views, view) {
      views = views.filter(function (v) { return v.stackId !== view.stackId; });
      views.push(view);
      return views;
  }
  function setForward(views, view) {
      var index = views.indexOf(view);
      if (index >= 0) {
          views = views.filter(function (v) { return v.stackId !== view.stackId || v.id <= view.id; });
      }
      else {
          views.push(view);
      }
      return views;
  }
  function setBack(views, view) {
      var index = views.indexOf(view);
      if (index >= 0) {
          return views.filter(function (v) { return v.stackId !== view.stackId || v.id <= view.id; });
      }
      else {
          return setRoot(views, view);
      }
  }
  export function getUrl(router, activatedRoute) {
      var urlTree = router.createUrlTree(['.'], { relativeTo: activatedRoute });
      return router.serializeUrl(urlTree);
  }
  export function isTabSwitch(enteringView, leavingView) {
      if (!leavingView) {
          return false;
      }
      return enteringView.stackId !== leavingView.stackId;
  }
  export function computeStackId(prefixUrl, url) {
      if (!prefixUrl) {
          return undefined;
      }
      var segments = toSegments(url);
      for (var i = 0; i < segments.length; i++) {
          if (i >= prefixUrl.length) {
              return segments[i];
          }
          if (segments[i] !== prefixUrl[i]) {
              return undefined;
          }
      }
      return undefined;
  }
  export function toSegments(path) {
      return path
          .split('/')
          .map(function (s) { return s.trim(); })
          .filter(function (s) { return s !== ''; });
  }
  export function destroyView(view) {
      if (view) {
          // TODO lifecycle event
          view.ref.destroy();
          view.unlistenEvents();
      }
  }
  