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

Catch root of subrouter #78

Closed
antonholmquist opened this issue Nov 16, 2014 · 3 comments
Closed

Catch root of subrouter #78

antonholmquist opened this issue Nov 16, 2014 · 3 comments
Labels

Comments

@antonholmquist
Copy link

The route below matches /

router := mux.NewRouter()
router.Methods("GET").Path("/").HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
    res.Write([]byte("/"))
})

If I want to match /subroute, shouldn't I be able to use this? It currently does not seem to work. Is this by design or a mistake?

subrouter := router.PathPrefix("/subroute").Subrouter()
subrouter.Methods("GET").Path("/").HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
    res.Write([]byte("/subroute"))
})
@chadkouse
Copy link

that will match /subroute/ -- I also would like to match /subroute with no trailing slash so I have to have additional routes outside of the subrouter to match those.

Ideally this would work:

subrouter := router.PathPrefix("/subroute").Subrouter()
subrouter.Methods("GET").Path("").HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
    res.Write([]byte("/subroute"))
})

but currently it does not.

@jonathaningram
Copy link

@chadkouse don't suppose you found a workaround did you?

@elithrar
Copy link
Contributor

See #215

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

No branches or pull requests

4 participants