What's Changed
UX Improvement: Auto-Group Creation in Route()
The Route() method now automatically creates a sub-group when called on the root bundle. This fixes a common UX issue where users would call router.Route(...) expecting isolated middleware scope but accidentally modify the root bundle's global middleware stack.
Before:
router := routegroup.New(http.NewServeMux())
router.Route(func(b *routegroup.Bundle) {
b.Use(middleware) // accidentally adds to root!
b.HandleFunc("/api", handler)
})After (v1.6.0):
router := routegroup.New(http.NewServeMux())
router.Route(func(b *routegroup.Bundle) {
b.Use(middleware) // now properly isolated to sub-group
b.HandleFunc("/api", handler)
})Breaking Change Note
This is technically a behavior change that may affect code relying on the old pattern of router.Route() modifying the root bundle directly. However, this old behavior was rarely the intended use case and often led to bugs.
The following patterns are now equivalent:
router.Route(fn)router.Group().Route(fn)
Existing code using router.Mount("/path").Route(fn) or router.Group().Route(fn) is unaffected.
Internal Fix
Fixed root bundle locking to properly maintain the Use-before-routes contract when routes are registered via Route() auto-wrapping.
Full Changelog: v1.5.3...v1.6.0