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

Router.NotFoundHandler is not used when the router is a subrouter #20

Closed
ghost opened this issue Apr 28, 2013 · 3 comments
Closed

Router.NotFoundHandler is not used when the router is a subrouter #20

ghost opened this issue Apr 28, 2013 · 3 comments
Labels

Comments

@ghost
Copy link

ghost commented Apr 28, 2013

I defined specific NotFoundHandler for several subrouters but the NotFoundHandler from the main Router is always used.

@kisielk
Copy link
Contributor

kisielk commented Jun 4, 2014

I looked at this today but there doesn't seem to be any obvious way to implement it. NotFoundHandler is only called from ServeHTTP, which is only ever called on the top-level router and not the subrouters. Furthermore there is no concept of a partial match, that is the top-level part of the subrouter path matching but the inner part not matching.

@error10
Copy link

error10 commented Jul 19, 2015

I've worked around this by using a PathPrefix() after the home page route for the subroute.

    r := mux.NewRouter()
    s := r.Host("{subdomain}." + domain).Subrouter()
    //...more routes..
    s.Handle("/", commonChain.Then(subdomainHomepageHandler()))
    s.PathPrefix("/").Handler(commonChain.Then(http.HandlerFunc(subdomainNotFound)))

Later, subdomainNotFound(), which for me does some extra work, will generate a (nicely templated) 404 if necessary.

@elithrar
Copy link
Contributor

elithrar commented Aug 8, 2015

I'm going to close this as wontfix: if you do need separate a NotFoundHandler you can use nested routers (via mux.NewRouter()). Happy to open it again if there's a desire to.

@elithrar elithrar closed this as completed Aug 8, 2015
bign8 pushed a commit to bign8/mux that referenced this issue Dec 25, 2015
bign8 added a commit to bign8/mux that referenced this issue Dec 25, 2015
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

3 participants