Repository navigation
docs(group): explain how group catch-all NotFound routes replace RouteNotFound handlers - #3155
Merged
Merged
Conversation
Group.Use registers catch-all "" and "/*" RouteNotFound routes so group middleware runs for unmatched paths, which replaces custom handlers that were registered for those paths earlier (#3153).
When a group has middlewares,
Group#Use()registers catch-allRouteNotFoundroutes for the group prefix and prefix +/*so that the middlewares also run for unmatched paths. A custom NotFound handler registered for those paths before that call is replaced. This is by design (#2411,TestGroup_RouteNotFoundWithMiddleware), but theGroup.RouteNotFounddoc did not say so.This documentation-only change adds a note to
Group.RouteNotFoundthat states the rule:Group#Use()call that leaves the group with middlewares (re)registers them with the group middlewares, unless the Echo-wideConfig.NoGroupAutoRegister404Routesis set.Echo#Group()andGroup#Group()make this call when the new group has own or inherited middlewares.Echo, and a handler registered later replaces them.RouterConfig.NotFoundHandler(seeTestGroup_RouteNotFoundUsesRouterConfig), or setConfig.NoGroupAutoRegister404Routesand register both paths yourself on the group whose middlewares should run for them.Every statement in the note was checked with throwaway tests against the default, non-overwriting,
NotFoundHandler, andConcurrentRouterrouter configurations.Refs #3153