title: Cannot get css/js files to load using custom router
body: <p>I've been working (mostly for fun) on a custom router.
  It's a work in progress, so any advice is always welcome!</p>
  
  <p>But my main problem is that de css/js files are not loaded anymore.
  It looks like the path to the files is attached to the current url, so users/(css path).</p>
  
  <p>In Chrome and Firefox the assets just keep loading, no response/code is returned. If I deliberately cause an exception to be thrown, such as altering the file path, I do see the html of the exception being returned.</p>
  
  <p>I've done a lot of debugging already, and cannot seem to figure it out.</p>
  
  <pre><code>    /**
   * @var
   */
  private $routes;
  /**
   * @var string
   * Todo: add this to an ini file or something
   */
  private $base_route = "/index.php";
  
  /**
   * @param $route
   * @param $callback
   * @param string $method
   */
  public function addRoute($route, $callback, $method = Route::GET)
  {
      $routes = $this-&gt;getRoutes();
      if (empty($routes) || !in_array($route, $routes)) {
          $this-&gt;setRoute(
              [
                  "route" =&gt; $route,
                  "callback" =&gt; $callback
              ], $method
          );
          return;
      }
  }
  
  /**
   * @param array $route
   * @param $method
   */
  public function setRoute(array $route, $method)
  {
      $this-&gt;routes[$method][] = $route;
  }
  
  /**
   * @return mixed
   */
  public function getRoutes()
  {
      return $this-&gt;routes;
  }
  
  /**
   * @throws \Exception
   */
  public function handle()
  {
      $route = $this-&gt;getURI();
      $route = str_replace($this-&gt;base_route, "", $route);
  
      $urlparts = explode("?", $route);
      if (count($urlparts) &gt; 1) {
          $route = $urlparts[0];
          $query = $urlparts[1];
      }
  
      if ($this-&gt;isAssetRoute($route)) {
          $parts = explode("/", $route);
          foreach ($parts as $part) {
              if ($part !== "public") {
                  unset($parts[$part]);
              } else {
                  continue;
              }
          }
          $route = implode($parts);
          return APP_PATH . "/" . $route;
      }
  
      if (empty($route)) {
          $this-&gt;executeCallback("HomeController");
          return;
      }
  
      $exists = false;
      $routes = $this-&gt;getRoutes();
      $requested_method = $this-&gt;getMethod();
  
      if (!isset($routes[$requested_method])) {
          throw new Exception("404: Route {$route} does not exist with method {$requested_method}");
      }
  
      $declared_routes = $routes[$requested_method];
      $count_routes = count($declared_routes);
  
      for ($i = 0; $i &lt; $count_routes; $i++) {
          if ($declared_routes[$i]["route"] === $route) {
              $exists = true;
              $data = $declared_routes[$i];
              continue;
          }
      }
  
      if (!$exists) {
          throw new \Exception("404: route {$route} does not exist!");
      }
  
      //Todo: replace [var]
      $route = $this-&gt;compileRoute($route);
  
      $this-&gt;executeCallback($data["callback"]);
  }
  
  /**
   * @return mixed
   */
  private function getProtocol()
  {
      return $_SERVER["HTTPS"];
  }
  
  /**
   * @return mixed
   */
  public function getMethod()
  {
      return $_SERVER["REQUEST_METHOD"];
  }
  
  /**
   * @return mixed
   */
  public function getURI()
  {
      return $_SERVER["REQUEST_URI"];
  }
  
  /**
   * @param $route
   * @param $callback
   */
  public function get($route, $callback)
  {
      $this-&gt;setRoute(
          [
              "route" =&gt; $route,
              "callback" =&gt; $callback
          ], Route::GET
      );
  }
  
  /**
   * @param $route
   * @param $callback
   */
  public function post($route, $callback)
  {
      $this-&gt;setRoute(
          [
              "route" =&gt; $route,
              "callback" =&gt; $callback
          ], Route::POST
      );
  }
  
  /**
   * @param $route
   * @return mixed
   */
  public function compileRoute(&amp;$route)
  {
      $uri = explode("/", $_SERVER["REQUEST_URI"]);
      $formatted_route = "";
      foreach ($uri as $key =&gt; $param) {
          $formatted_route .= "/" . preg_replace(
                  "/\[(.*)\]/", "1", $param
              );
      }
      return str_replace($this-&gt;base_route, "", $formatted_route);
  }
  
  /**
   * @param $callback
   * @throws \Exception
   */
  public function executeCallback($callback)
  {
      $callback_data = explode("::", $callback);
  
      $controller = $callback_data[0];
      if (!isset($callback_data[1])) {
          $method = "index";
      } else {
          $method = $callback_data[1];
      }
  
      if (!class_exists($controller)) {
          throw new \Exception("Class {$controller} does not exist!");
      }
  
      if (!method_exists($controller, $method)) {
          throw new \Exception("Method {$method} does not exist!");
      }
  
      $controller::$method();
  }
  
  /**
   * @param $route
   * @return bool
   */
  private function isAssetRoute($route)
  {
      return (stripos($route, "/public/assets/") !== false);
  }
  </code></pre>