Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overlapping routes with differing methods cause a panic #1498

Closed
kekeimiku opened this issue Oct 21, 2022 · 3 comments
Closed

Overlapping routes with differing methods cause a panic #1498

kekeimiku opened this issue Oct 21, 2022 · 3 comments

Comments

@kekeimiku
Copy link

kekeimiku commented Oct 21, 2022

Bug Report

Version

axum 0.6.0-rc.2

Platform

Linux manjaro 5.15.74-3-MANJARO x86_64 GNU/Linux

Crates

[dependencies.axum]
version = "0.6.0-rc.2"
default-features = false
features = ["headers", "json", "http2"]

Description

Router::with_state(db)
        .route("/category", post(add_category))
        .route("/category/:num/:size", get(category_list))
        .route("/category/:id", delete(del_category))
thread 'main' panicked at 'Invalid route "/category/:id": insertion failed due to conflict with previously registered route: /category/:num/:size',
@jplatte
Copy link
Member

jplatte commented Oct 21, 2022

This is a known limitation, if you have multiple /foo/:param(/...) routes, the param name must always be the same. This limitation comes from the underlying routing library, matchit, and has an issue at ibraheemdev/matchit#13.

@jplatte jplatte closed this as not planned Won't fix, can't repro, duplicate, stale Oct 21, 2022
@BratSinot
Copy link

This is a known limitation, if you have multiple /foo/:param(/...) routes, the param name must always be the same. This limitation comes from the underlying routing library, matchit, and has an issue at ibraheemdev/matchit#13.

Also, another variant:

use axum::{
    routing::{get, post},
    Router,
};

fn main() {
    /* these are configurable */
    let base_path = "/";
    let get_base_path = "/";
    let post_base_path = "/";

    let get_route = Router::new().nest(
        get_base_path,
        Router::new().route("/get", get(|| std::future::ready("Ho".to_owned()))),
    );
    let post_route = Router::new().nest(
        post_base_path,
        Router::new().route("/post", post(|| std::future::ready("Ho".to_owned()))),
    );
    let app: Router<String> =
        Router::new().nest(base_path, Router::new().merge(get_route).merge(post_route));
}

cause this error:

thread 'main' panicked at 'Invalid route "/": insertion failed due to conflict with previously registered route: /*__private__axum_nest_tail_param', src/main.rs:21:70
stack backtrace:

@davidpdrsn
Copy link
Member

@BratSinot Please open a new issue 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants