{"action":"created","issue":{"url":"https://api.github.com/repos/pressly/chi/issues/31","labels_url":"https://api.github.com/repos/pressly/chi/issues/31/labels{/name}","comments_url":"https://api.github.com/repos/pressly/chi/issues/31/comments","events_url":"https://api.github.com/repos/pressly/chi/issues/31/events","html_url":"https://github.com/pressly/chi/issues/31","id":128700175,"number":31,"title":"Subrouter hides parent routes","user":{"login":"VojtechVitek","id":139342,"avatar_url":"https://avatars.githubusercontent.com/u/139342?v=3","gravatar_id":"","url":"https://api.github.com/users/VojtechVitek","html_url":"https://github.com/VojtechVitek","followers_url":"https://api.github.com/users/VojtechVitek/followers","following_url":"https://api.github.com/users/VojtechVitek/following{/other_user}","gists_url":"https://api.github.com/users/VojtechVitek/gists{/gist_id}","starred_url":"https://api.github.com/users/VojtechVitek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/VojtechVitek/subscriptions","organizations_url":"https://api.github.com/users/VojtechVitek/orgs","repos_url":"https://api.github.com/users/VojtechVitek/repos","events_url":"https://api.github.com/users/VojtechVitek/events{/privacy}","received_events_url":"https://api.github.com/users/VojtechVitek/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-01-26T02:11:40Z","updated_at":"2016-01-26T02:29:54Z","closed_at":null,"body":"```go\r\npackage main\r\n\r\nimport (\r\n\t\"log\"\r\n\t\"net/http\"\r\n\r\n\t\"github.com/pressly/chi\"\r\n)\r\n\r\nfunc main() {\r\n\tr := chi.NewRouter()\r\n\r\n\t// Parent route -- /foo\r\n\tr.Get(\"/foo\", func(w http.ResponseWriter, r *http.Request) {\r\n\t\tlog.Println(\"/foo\")\r\n\t})\r\n\r\n\t// Subrouter -- defining /foo/bar\r\n\tr.Mount(\"/foo\", subrouter())\r\n\r\n\thttp.ListenAndServe(\":3333\", r)\r\n}\r\n\r\nfunc subrouter() http.Handler {\r\n\tr := chi.NewRouter()\r\n\tr.Get(\"/bar\", func(w http.ResponseWriter, r *http.Request) {\r\n\t\tlog.Println(\"/foo/bar\")\r\n\t})\r\n\treturn r\r\n}\r\n```\r\n\r\n1) `$ curl -v localhost:3333/foo`\r\n    \r\n        > GET /foo HTTP/1.1\r\n        < HTTP/1.1 404 Not Found\r\n        Not Found\r\n    \r\n    The route **wasn't matched** -- seems like the subrouter hid it.\r\n\r\n2) `$ curl -v localhost:3333/foo/`\r\n    \r\n        > GET /foo/ HTTP/1.1\r\n        < HTTP/1.1 404 Not Found\r\n        404 page not found\r\n    \r\n    Again.. but with **different body** -- different NotFound handler?\r\n\r\n3) `$ curl -v localhost:3333/foo/bar`\r\n    \r\n        > GET /foo/bar HTTP/1.1\r\n        < HTTP/1.1 200 OK\r\n        /foo/bar\r\n    \r\n    OK"},"comment":{"url":"https://api.github.com/repos/pressly/chi/issues/comments/174783148","html_url":"https://github.com/pressly/chi/issues/31#issuecomment-174783148","issue_url":"https://api.github.com/repos/pressly/chi/issues/31","id":174783148,"user":{"login":"VojtechVitek","id":139342,"avatar_url":"https://avatars.githubusercontent.com/u/139342?v=3","gravatar_id":"","url":"https://api.github.com/users/VojtechVitek","html_url":"https://github.com/VojtechVitek","followers_url":"https://api.github.com/users/VojtechVitek/followers","following_url":"https://api.github.com/users/VojtechVitek/following{/other_user}","gists_url":"https://api.github.com/users/VojtechVitek/gists{/gist_id}","starred_url":"https://api.github.com/users/VojtechVitek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/VojtechVitek/subscriptions","organizations_url":"https://api.github.com/users/VojtechVitek/orgs","repos_url":"https://api.github.com/users/VojtechVitek/repos","events_url":"https://api.github.com/users/VojtechVitek/events{/privacy}","received_events_url":"https://api.github.com/users/VojtechVitek/received_events","type":"User","site_admin":false},"created_at":"2016-01-26T02:29:54Z","updated_at":"2016-01-26T02:29:54Z","body":"Since I'm not overwriting the parent /foo path in the subrouter, I'd expect it to be matched and served anyways. Consider applying different middlewares for anonymous and auth'd routes from the parent router:\r\n\r\n```go\r\nfunc main() {\r\n\tr := chi.NewRouter()\r\n\r\n\tr.Group(func(r chi.Router) {\r\n\t\tr.Use(InjectAnonymousToken)\r\n\t\t\r\n\t\tr.Get(\"/\", PublicRoutes())\r\n\t})\r\n\r\n\tr.Group(func(r chi.Router) {\r\n\t\tr.Use(TokenRefresh)\r\n\t\tr.Use(Authenticator)\r\n\r\n\t\tr.Mount(\"/\", AuthRoutes())\r\n\t})\r\n\r\n\thttp.ListenAndServe(\":3333\", r)\r\n}\r\n```\r\n\r\nIt would be nice to be able to \"merge\" those subroutes into a single matching route."}}