<commit_before>module.exports = {
  routes: [],

  route: {
    url: '',
    args: [],
    component: {}
  },

  init(routes) {
    this.routes = routes.map(route => {
      route.url = typeof route.url === 'string' ? new RegExp(`^${route.url}$`) : route.url;
      return route;
    });

    this.parse(location.hash);
  },

  redirect(url) {
    history.replaceState({}, '', `#${url}`);
    this.parse(url);
  },

  parse(url, routes = this.routes) {
    const path = url.replace(/^[^#]*#/, '');
    const route = routes.find(route => route.url.test(path));

    if (route) {
      const newRoute = {
        url: path,
        args: route.url.exec(path).slice(1),
        component: route.component
      };

      if (route.redirect) {
        if (typeof route.redirect === 'function') {
          route.redirect(newRoute)
            .then(url => this.redirect(url))
            .catch(e => {
              console.error(e);
              history.back();
            });
        } else {
          this.redirect(route.redirect);
        }
      } else if (route.before) {
        route.before(newRoute)
          .then(() => this.setRoute(newRoute, route.after))
          .catch(() => this.parse(url, routes.slice(routes.indexOf(route) + 1)));
      } else {
        this.setRoute(newRoute, route.after);
      }
    } else {
      this.setRoute({
        url: path,
        args: [],
        component: {}
      });
    }
  },

  setRoute(route, after) {
    const oldRoute = this.route;
    this.route = route;
    if (typeof after === 'function') {
      after(oldRoute, route);
    }
  },

  install(Vue) {
    Object.defineProperty(Vue.prototype, '$router', {get: () => this});
    Object.defineProperty(Vue.prototype, '$route', {get: () => this.route});

    Vue.util.defineReactive(this, 'route', this.route);

    window.addEventListener('hashchange', e => this.parse(e.newURL));
  }
};
<commit_msg>Removed logging on redirect reject<commit_after>module.exports = {
  routes: [],

  route: {
    url: '',
    args: [],
    component: {}
  },

  init(routes) {
    this.routes = routes.map(route => {
      route.url = typeof route.url === 'string' ? new RegExp(`^${route.url}$`) : route.url;
      return route;
    });

    this.parse(location.hash);
  },

  redirect(url) {
    history.replaceState({}, '', `#${url}`);
    this.parse(url);
  },

  parse(url, routes = this.routes) {
    const path = url.replace(/^[^#]*#/, '');
    const route = routes.find(route => route.url.test(path));

    if (route) {
      const newRoute = {
        url: path,
        args: route.url.exec(path).slice(1),
        component: route.component
      };

      if (route.redirect) {
        if (typeof route.redirect === 'function') {
          route.redirect(newRoute)
            .then(url => this.redirect(url))
            .catch(() => history.back());
        } else {
          this.redirect(route.redirect);
        }
      } else if (route.before) {
        route.before(newRoute)
          .then(() => this.setRoute(newRoute, route.after))
          .catch(() => this.parse(url, routes.slice(routes.indexOf(route) + 1)));
      } else {
        this.setRoute(newRoute, route.after);
      }
    } else {
      this.setRoute({
        url: path,
        args: [],
        component: {}
      });
    }
  },

  setRoute(route, after) {
    const oldRoute = this.route;
    this.route = route;
    if (typeof after === 'function') {
      after(oldRoute, route);
    }
  },

  install(Vue) {
    Object.defineProperty(Vue.prototype, '$router', {get: () => this});
    Object.defineProperty(Vue.prototype, '$route', {get: () => this.route});

    Vue.util.defineReactive(this, 'route', this.route);

    window.addEventListener('hashchange', e => this.parse(e.newURL));
  }
};

{'fraction_non_alphanumeric': 0.1846763540290621, 'fraction_numerical': 0.0010568031704095112, 'mean_word_length': 2.1949367088607596, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4371356', 'n_tokens_mistral': 1225, 'n_tokens_neox': 1210, 'n_words': 213}