Description
I have few routes and I want to redirect to another route from the handler of a particular route
Sample:
func ApiRouter(r *gin.Engine) { r.Use(middleware.VerifyUserFromToken()) work := r.Group("/api/work") { work.POST("", Work.Create) work.PUT("/:pbk", Work.Update) work.DELETE("/:pbk", Work.Delete) work.GET("/get", Work.Get) } }
// Work.Update method
func Update(c *gin.Context) { // logics
// c.JSON(http.StatusOK, response) this works well.
c.Reidrect(http.StatusFound, "api/work/get") // this returns 404. }
Please I need help with this
Environment
- go version: go 1.18
- gin version (or commit ref):
- operating system: Ubuntu
Comment From: GanymedeNil
The jump address can be either a relative path or an absolute path. In the case you gave, the absolute path looks like this c.Reidrect(http.StatusFound, "/api/work/get"), while the relative path looks like this c.Reidrect(http.StatusFound, "get").