matchit icon indicating copy to clipboard operation
matchit copied to clipboard

CatchAll(/*) don't works

Open taikulawo opened this issue 1 year ago • 4 comments

Hi. I need a catch all route /*, but I don't care params.

#[test]
    fn test_route_path_match() {
        let mut router = Router::new();
        // works
        router.insert("/{*p}", "Catch All Workaround").unwrap();
        let matched = router.at("/endpoints/foo/bar").unwrap();
        assert_eq!(*matched.value, "Catch All Workaround");
        // panic
        let mut router = Router::new();
        router.insert("/*", "Catch All").unwrap();
        let matched = router.at("/endpoints/foo/bar").unwrap();
        assert_eq!(*matched.value, "Catch All");
    }

taikulawo avatar Nov 07 '24 09:11 taikulawo

/* is not supported syntax, all parameters must have a name. Is there a reason you don't want to provide a name?

ibraheemdev avatar Nov 07 '24 10:11 ibraheemdev

I don't use params, just want to catch all

taikulawo avatar Nov 07 '24 11:11 taikulawo

I suppose /{*} is reasonable but I'd suggest you use a placeholder name for now as this is relatively low priority.

ibraheemdev avatar Nov 07 '24 11:11 ibraheemdev

One use case of this pattern is for simple nesting of router where a /foo/{*} or foo/* will catch both /foo/ and foo/{*p}. I'm using it in my web framework so I can write Router::new().insert("/foo", Router::new())

fakeshadow avatar Nov 11 '24 21:11 fakeshadow