fn get_template_for_path<'a, G: Html>(
    path: &str,
    render_cfg: &HashMap<String, String>,
    entities: &'a EntityMap<G>,
) -> (Option<&'a Forever<Entity<G>>>, bool) {
    let mut was_incremental_match = false;
    // Match the path to one of the entities
    let mut entity_name = None;
    // We'll try a direct match first
    if let Some(entity_root_path) = render_cfg.get(path) {
        entity_name = Some(entity_root_path.to_string());
    }
    // Next, an ISR match (more complex), which we only want to run if we didn't get
    // an exact match above
    if entity_name.is_none() {
        // We progressively look for more and more specificity of the path, adding each
        // segment. That way, we're searching forwards rather than backwards,
        // which is more efficient.
        let path_segments: Vec<&str> = path.split('/').collect();
        for (idx, _) in path_segments.iter().enumerate() {
            // Make a path out of this and all the previous segments
            let path_to_try = path_segments[0..(idx + 1)].join("/") + "/*";

            // If we find something, keep going until we don't (maximize specificity)
            if let Some(entity_root_path) = render_cfg.get(&path_to_try) {
                was_incremental_match = true;
                entity_name = Some(entity_root_path.to_string());
            }
        }
    }
    // If we still have nothing, then the page doesn't exist, *unless* there's
    // incremental generation on the index template, in which case it does
    // (this doesn't break priorities because, above, we go for the most specific,
    // and this is the least, meaning there is nothing more specific)
    if let Some(entity_name) = entity_name {
        (entities.get(&entity_name), was_incremental_match)
    } else if render_cfg.contains_key("/*") {
        (entities.get(""), true)
    } else {
        (None, was_incremental_match)
    }
}
Determines the template to use for the given path by checking against the
render configuration, also returning whether we matched a simple page or an
incrementally-generated one (`true` for incrementally generated). Note that
simple pages include those on incrementally-generated templates that we
pre-rendered with *build paths* at build-time (and are hence in an immutable
store rather than a mutable store).

This houses the central routing algorithm of Perseus, which is based fully
on the fact that we know about every single page except those rendered with
ISR, and we can infer about them based on template root path domains. If
that domain system is violated, this routing algorithm will not behave as
expected whatsoever (as far as routing goes, it's undefined behavior)!
packages/perseus/src/router/match_route.rs