title: Nested Gorilla Mux router does not work
body: <p>Using code below, when I access /test2 it responds with 404 - not found. /test1 works correctly. Why is that? Is nesting not allowed despite the fact that routers implement http.Handler interface?</p>
  
  <pre><code>package main
  
  import (
      "fmt"
      "net/http"
      "github.com/gorilla/mux"
  )
  
  func main() {
  
      mainRouter := mux.NewRouter()
      subRouter := mux.NewRouter()
  
      mainRouter.HandleFunc("/test1", func(w http.ResponseWriter, r *http.Request) { fmt.Fprint(w, "test1") })
  
      subRouter.HandleFunc("/test2", func(w http.ResponseWriter, r *http.Request) { fmt.Fprint(w, "test2") })
  
      mainRouter.Handle("/", subRouter)
  
      http.ListenAndServe(":9999", mainRouter)
  }
  </code></pre>
  
  <p><strong>EDIT:</strong></p>
  
  <p>My main goal was to add some initial work which would be common for all routes in subRouter, and only for them. To be even more specific, I would like to use <a href="https://github.com/codegangsta/negroni" rel="noreferrer">Negroni</a> as my middleware orchiestrator.
  On the Negroni website there is an example of adding middleware to the group of routes:</p>
  
  <pre><code>router := mux.NewRouter()
  adminRoutes := mux.NewRouter()
  // add admin routes here
  
  Create a new negroni for the admin middleware
  router.Handle("/admin", negroni.New(
    Middleware1, 
    Middleware2, 
    negroni.Wrap(adminRoutes),
  )) 
  </code></pre>
  
  <p>Negroni basically executes ServeHTTP methods of every argument, since all of them implement http.Handler. It executes them in order, so router routes will be last.</p>
  
  <p>I'm familiar with the concept of <code>Subrouter</code> in Mux, but AFAIK I can't use it in similar fashion as example above, in particular, I can't inject anything between mainRouter and its <code>Subrouter</code>. This is why nesting looks more flexible. </p>