takes routes and decorates them with a 'match' method that will return { params, query } if a path matches
182366
function addMatch (route) {
  let routePath = route.path
  let paramNames = []
  let matched
  // find any paths prefixed with `:` or `%`, and treat them as capture groups
  while ((matched = routePath.match(paramPattern)) !== null) {
    routePath = routePath.replace(paramPattern, '([^?/]+)')
    paramNames.push(matched[1])
  }
  // if a route ends with `index`, allow matching that route without matching the `index` part
  if (path.basename(routePath) === 'index') {
    route.isIndex = true
    routePath = routePath.replace(/\/index$/, '/?([:%]?index)?')
  }
  // create a regex with our path
  let pattern = new RegExp(`^${routePath}(\\?(.*)|$)`, 'i')
  route.pattern = pattern
  route.match = url => {
    let m = url.match(pattern)
    if (m) {
      let params = paramNames.reduce((o, p, idx) => {
        o[p] = m[idx + 1]
        return o
      }, {})
      let query = qs.parse(m[m.length - 1])
      return { params, query }
    }
  }
  return route
}
1228662
function getRoute (routes, type) {
  if (!routes) return null;
  return Object.keys(routes).reduce(function (match, route) {
    return getRouteType(route) === type ? route : match;
  }, null);
}
1035895
def _match_view(self, method, route_params):
        
        method = method.upper()
        route_params = frozenset(k for k, v in route_params.items() if v is not None)

        for view_name, info in self.methods_map[method].items():
            if info.matches(method, route_params):
                return getattr(self, view_name)
        else:
            return None
694780
function getMatchedRoute(children, pathname) {
  return React.Children.toArray(children).find(child => {
    return matchPath(pathname, {
      exact: child.props.exact,
      path: child.props.path,
    });
  }) || NO_MATCH;
}
1204539
def get_matches(path)
      matches = []

      @routes.each_with_index do |route, i|
        score, pars = score_route(route[:parts], path)
        matches << [i, score, pars] if score > 0
      end

      matches
    end
1081932
function(context) {

            // Check path
            var path = context.request.urlInfo.pathname;

            if (path.indexOf(this.$.path) === 0) {
                // path matches
                if (this.$.route !== null) {
                    return (new RegExp(this.$.route, "i")).test(path);
                }

                return true;
            }

            return false;
        }
745044
def match(env)
      routes[env[Rack::REQUEST_METHOD]]
        .lazy # Lazy to avoid unnecessary calls to #match.
        .map { |r| r.match(env) }
        .find { |r| !r.nil? }
    end
1364050
function isActive(_ref, indexOnly, currentLocation, routes, params) {
  var pathname = _ref.pathname;
  var query = _ref.query;

  if (currentLocation == null) return false;

  // TODO: This is a bit ugly. It keeps around support for treating pathnames
  // without preceding slashes as absolute paths, but possibly also works
  // around the same quirks with basenames as in matchRoutes.
  if (pathname.charAt(0) !== '/') {
    pathname = '/' + pathname;
  }

  if (!pathIsActive(pathname, currentLocation.pathname)) {
    // The path check is necessary and sufficient for indexOnly, but otherwise
    // we still need to check the routes.
    if (indexOnly || !routeIsActive(pathname, routes, params)) {
      return false;
    }
  }

  return queryIsActive(query, currentLocation.query);
}
1280995
def request_matches_route(self, actual_route: str, expected_route: str):
        
        expected_params = self.get_url_params(expected_route)
        actual_params = self.get_url_params(actual_route)
        i = 0

        if len(expected_params) == len(actual_params):
            for param in actual_params:
                if expected_params[i][0] != "{":
                    if param != expected_params[i]:
                        return False
                i += 1
        else:
            return False

        return True
299058
function generatePath(route, params) {
    return route.pattern.replace(nameOrSplatParam, function(_, name) { return params[name]; });
  }
487757
function makePath(to, params, query) {
        var path;
        if (PathUtils.isAbsolute(to)) {
          path = to;
        } else {
          var route = to instanceof Route ? to : Router.namedRoutes[to];

          invariant(route instanceof Route, 'Cannot find a route named "%s"', to);

          path = route.path;
        }

        return PathUtils.withQuery(PathUtils.injectParams(path, params), query);
      }
40283
function match(routes, path) {

  // Get the query object before it gets stripped by the normalizer
  const query = getQuery(path);
  const pathname = path;

  // Normalize the path
  path = normalizePath(path);

  // Loop over each route to find the match
  for (let i = 0; i < routes.length; i++) {

    // Normalize the current route
    const currentRoute = normalizePath(routes[i].route);

    // Create the params object
    const params = {};

    // Check if it's a straight match first
    if(currentRoute === path) {
      return Object.assign({}, routes[i], {params, query, pathname, path});
    }

    // If there are no dynamic/optional/match-all parts then this route cannot match
    if(!isDynamicRoute.test(routes[i].route)) {
      continue;
    }

    // Split up the route by it's slashes so that we may match by section
    const routeSections = currentRoute.split('/');
    const pathSections = path.split('/');

    // Loop over each section looking for a full match
    for (let j = routeSections.length - 1; j >= 0; j--) {

      // If the route is to match everything, then return
      if(j === 0 && routeSections[j] === '*') {
        return Object.assign({}, routes[i], {params, query, pathname, path});
      }

      // If this section is optional
      if(optionalSectionRegex.test(routeSections[j])) {

        const currentSection = routeSections[j].replace(removeOptionalRegex, '');

        // If it's a param, add it to the params
        if(paramRegex.test(currentSection)) {
          params[currentSection.replace(paramRegex, '')] = pathSections[j];
          continue;
        }

        // If it's a star then skip to next
        if(currentSection === '*') {
          continue;
        }

        // If the optional section can possible be missing skip to next section
        if(routeSections.length === pathSections.length + 1) {
          continue;
        }

        // If the path and route sections have same number of sections and this does match, skip to next
        if(routeSections.length === pathSections.length && currentSection === pathSections[j]) {
          continue;
        }

        // Reject this route as the possible match to the path
        break;
      }

      // If it's a param, add it to the params
      if(paramRegex.test(routeSections[j])) {
        params[routeSections[j].replace(paramRegex, '')] = pathSections[j];

        if(j === 0) {
          return Object.assign({}, routes[i], {params, query, pathname, path});
        }

        continue;
      }

      // If it's a star then skip to next
      if(routeSections[j] === '*') {
        continue;
      }

      // If this doesn't match then go to next route
      if(routeSections[j] !== pathSections[j]) {
        break;
      }

      // If the last item matches strictly then return that match
      if(j === 0 && routeSections[j] === pathSections[j]) {
        return Object.assign({}, routes[i], {params, query, pathname, path});
      }
    }
  }

  // No match found
  return {path: '', params: {}, query};
}
692021
function applyRoutes(cmd, route, _app) {
    cmd = cmd.split(' ');
    var url = cmd[1] || cmd[0];
    var method = cmd.length < 2 ? 'get' : cmd[0];

    // Support regex expression
    var matches = /\((.*)\)/.exec(url);
    if(matches !== null && matches[1]) {
        url = new RegExp(matches[1]);
    }

    _app[method](url, function(req, res, next) {
        route.call({
            app: _app, req: req, res: res, next: next,
            //TODO:
            render: _app.get('render manager').list(res)
        }, req, res, next);
    });
}
493660
function(uri) {
        var route = this.defined(uri);
        if (route !== false) {

            if (this._routes[route].method === null) {
                var f = this._routes[route].handler.bind(this._routes[route].handler);
                f(this.params(route));
            } else {
                var Obj = this._routes[route].handler;
                var method = this._routes[route].method;
                Obj[method](this.params(route));
            }

        } else {
            console.error('Route "' + uri + '" is not defined.');
            return false;
        }
    }
523374
def match_url(self, path, method='GET'):
        
        path = path.strip().lstrip('/')
        handler, param = self.routes.match(method + ';' + path)
        if handler: return handler, param
        if method == 'HEAD':
            handler, param = self.routes.match('GET;' + path)
            if handler: return handler, param
        handler, param = self.routes.match('ANY;' + path)
        if handler: return handler, param
        return None, {}
428462
function(route, args, base) {
            base = base || "";
            args = args || {};
            var url = route;
            url = url.replace("#!/","#").replace("#!", "#").replace("#", "");
            _.map(args, function(value, attr) {
                url = url.replace("\:"+attr, value);
            });
            return base+"#/"+url;
        }
531097
def match(path)
      m = path.match(@rx)
      Match.new(remaining_path(path, m), match_to_params(m)) if m
    end