{"id":"3bb6faae19ddca7b","repo":"labstack/echo","slug":"adding-duplicate-route-same-method-path-is-not-a","errorCode":null,"errorMessage":"adding duplicate route (same method+path) is not allowed","messagePattern":"adding duplicate route \\(same method\\+path\\) is not allowed","errorType":"validation","errorClass":"AddRouteError","httpStatus":null,"severity":"error","filePath":"router.go","lineNumber":529,"sourceCode":"\tif route.Handler == nil {\n\t\tswitch route.Method {\n\t\tcase RouteNotFound:\n\t\t\troute.Handler = r.notFoundHandler\n\t\tcase http.MethodOptions:\n\t\t\troute.Handler = r.optionsMethodHandler\n\t\tdefault:\n\t\t\treturn RouteInfo{}, newAddRouteError(route, errors.New(\"adding route without handler function\"))\n\t\t}\n\t}\n\n\tmethod := route.Method\n\tpath := normalizePathSlash(route.Path)\n\n\th := applyMiddleware(route.Handler, route.Middlewares...)\n\tif !allowOverwritingRoute {\n\t\tfor _, rr := range r.routes {\n\t\t\tif route.Method == rr.Method && route.Path == rr.Path {\n\t\t\t\treturn RouteInfo{}, newAddRouteError(route, errors.New(\"adding duplicate route (same method+path) is not allowed\"))\n\t\t\t}\n\t\t}\n\t}\n\tvar headH HandlerFunc\n\tif r.autoHandleHEAD && method == http.MethodGet {\n\t\theadH = wrapHeadHandler(h)\n\t}\n\n\tparamNames := make([]string, 0)\n\toriginalPath := path\n\twasAdded := false\n\tvar ri RouteInfo\n\tfor i, lcpIndex := 0, len(path); i < lcpIndex; i++ {\n\t\tif path[i] == paramLabel {\n\t\t\tif i > 0 && path[i-1] == '\\\\' {\n\t\t\t\tpath = path[:i-1] + path[i:]\n\t\t\t\ti--\n\t\t\t\tlcpIndex--","sourceCodeStart":511,"sourceCodeEnd":547,"githubUrl":"https://github.com/labstack/echo/blob/05489dc1730161df26b72d1ae2a3ba6fb8178fc7/router.go#L511-L547","documentation":"Returned by DefaultRouter.Add (router.go:526-531) when a route with the same Method and Path is already registered and overwriting is disabled. The check is a linear scan of r.routes for an exact Method+Path match; AllowOverwritingRoute on the router (or allowOverwrite on the Route) bypasses it.","triggerScenarios":"Registering e.GET(\"/users\", h) twice; two route groups whose prefixes concatenate to the same final path; re-registration loops; reloading routes without enabling AllowOverwritingRoute.","commonSituations":"Hot-reload/plugin systems, generated routers, group prefix collisions (group \"/api\" + route \"/api/users\"), loops that register twice.","solutions":["Set RouterConfig.AllowOverwritingRoute = true (or per-route allowOverwrite) if the replacement is intentional","Remove the prior route with e.Router().Remove before re-adding","Dedupe registration loops and audit group prefix composition"],"exampleFix":"// before\ne.GET(\"/users\", h1)\n_, err := e.GET(\"/users\", h2) // error\n// after\nrouter := echo.NewRouter(echo.RouterConfig{AllowOverwritingRoute: true})\n// or, on an existing router:\ne.Router().(*echo.DefaultRouter).AllowOverwritingRoute = true\ne.GET(\"/users\", h2)","handlingStrategy":"validation","validationCode":"for _, r := range e.Routes() {\n    if r.Method == route.Method && r.Path == route.Path {\n        _ = e.Router().Remove(route.Method, route.Path)\n        break\n    }\n}\n_, err := e.Router().Add(route)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Enable AllowOverwritingRoute during dynamic registration","Dedupe route lists before bulk Add","Audit group prefix composition for collisions"],"tags":["routing","duplicate"],"analyzedSha":"05489dc1730161df26b72d1ae2a3ba6fb8178fc7","analyzedAt":"2026-08-04T21:32:47.783Z","schemaVersion":2}