You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Accessing a non-existent route, but passing through the middleware first, this situation also applies to route groups
There is usually an authorization authentication in the middleware. If you access a non-existent route, it will go through the middleware first, which will waste unnecessary processing and add additional judgment logic.
The text was updated successfully, but these errors were encountered:
c.Path() will return empty string if there is no route match. NB: if e.RouteNotFound() exists and is matched - it will have path.
e.RouteNotFound() also takes effect after the middleware, and needs to be manually processed in the middleware
e:=echo.New()
e.RouteNotFound("/*", func(c echo.Context) error {
log.Println("404 not found")
returnc.NoContent(http.StatusNotFound)
})
e.Use(func(next echo.HandlerFunc) echo.HandlerFunc {
returnfunc(c echo.Context) error {
// In the route group, /group/* will be returned, and you still need to manually match the routing table.// This method is not applicableifc.Path() =="" {
returnecho.NewHTTPError(http.StatusNotFound, "Not Found")
}
log.Println(c.Path(), "middleware...")
returnnext(c)
}
})
e.GET("/hello", func(c echo.Context) error {
returnc.String(http.StatusOK, "Hello, World!")
})
e.Logger.Fatal(e.Start(":1323"))
http://127.0.0.1:1323/test
Accessing a non-existent route, but passing through the middleware first, this situation also applies to route groups
There is usually an authorization authentication in the middleware. If you access a non-existent route, it will go through the middleware first, which will waste unnecessary processing and add additional judgment logic.
The text was updated successfully, but these errors were encountered: