Redirect for subrouters
Author: shamilovstasCreated May 17, 2025Updated Jan 2, 2026
Commented here, but since the issue cannot be reopened, I opened this issue to continue the discussion.
Copy of my comment there:
I'm not sure whether my question relates to the initial question, but perhaps it makes sense when subrouters are used? Consider this:
router.Route("/{username}", func(r chi.Router) { r.Get("/", func(w http.ResponseWriter, request *http.Request) { // r.Redirect("/details") <---- This is where I want to redirect to, keeping the subrouter's prefix (/{username}). }) r.Get("/details", func(writer http.ResponseWriter, request *http.Request) { // ... <---- Redirects here }) }
Originally posted by @shamilovstas in #709
Source: go-chi/chi