Skip to content

fix: inherit parent RouteNotFound handler for groups with middleware#2986

Closed
wyf027 wants to merge 1 commit into
labstack:v4from
wyf027:fix/group-routenotfound-fallback-2485
Closed

fix: inherit parent RouteNotFound handler for groups with middleware#2986
wyf027 wants to merge 1 commit into
labstack:v4from
wyf027:fix/group-routenotfound-fallback-2485

Conversation

@wyf027

@wyf027 wyf027 commented May 25, 2026

Copy link
Copy Markdown

Summary

  • When Group.Use() registers catch-all RouteNotFound routes for middleware execution, inherit the most specific parent RouteNotFound handler from the router tree
  • Fall back to the default NotFoundHandler only when no parent handler exists

Fixes #2485

Problem

Groups created with middleware always registered the default JSON NotFoundHandler for 404 cases, shadowing a custom root RouteNotFound handler.

Test plan

  • go test ./...
  • Added TestGroupRouteNotFoundFallsBackToRootHandler from the issue reproducer
  • Updated TestGroup_RouteNotFoundWithMiddleware expectations for inherited handlers

When a group registers middleware, reuse the most specific parent
RouteNotFound handler instead of always falling back to the default
JSON NotFoundHandler.

Fixes #2485
@wyf027
wyf027 force-pushed the fix/group-routenotfound-fallback-2485 branch from 3081f5e to 52f5079 Compare May 26, 2026 04:39
@aldas

aldas commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Closing, this PR is against v4 branch and we do not accept new features in v4, only security and bug related changes are accepted.

this can be argued that it is a bugfix but it also introduces new feature.

@aldas aldas closed this Jun 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants