{"size": 682, "ext": "js", "max_stars_repo_path": "src/router/index.js", "max_stars_repo_name": "lawun330/dev-house", "max_stars_repo_stars_event_min_datetime": "2020-05-16T19:22:25.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-11T05:37:02.000Z", "max_issues_repo_path": "src/router/index.js", "max_issues_repo_name": "lawun330/dev-house", "max_issues_repo_issues_event_min_datetime": "2020-05-17T04:52:53.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-27T04:50:26.000Z", "max_forks_repo_path": "src/router/index.js", "max_forks_repo_name": "lawun330/dev-house", "max_forks_repo_forks_event_min_datetime": "2020-05-16T18:08:08.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-08T11:43:06.000Z"}
{"max_stars_count": 9, "max_issues_count": 7, "max_forks_count": 23, "avg_line_length": 28.4166666667, "max_line_length": 77, "alphanum_fraction": 0.6524926686}
/*
  ~ This is Our JavaScript Custom Router
  ~ Feel free to use
*/
import ErrorPage from '../views/ErrorPage';

export function Route(routes) {
  const parseLocation = hash => hash.slice(1).toLowerCase() || "/";

  const findComponentByPath = path =>
    routes.find(r => r.path.match(new RegExp(`^\\${path}$`, "gm"))) || false;
  
  const router = () => {
    const path = parseLocation(document.location.hash);
    const { component = ErrorPage } =
      findComponentByPath(path, routes) || {};
    document.getElementById("root").innerHTML = component.render();
  };
  
  window.addEventListener("hashchange", router);
  window.addEventListener("load", router) || router();
}

