Middleware redirect with empty page


#1

I testing a redirect about echo when I just use the method to redirect it can show the login.html page successfully, but if I use a middleware test, it always shows empty page of login.html, what am I missing?

 e.Group("*.html", func(next echo.HandlerFunc) echo.HandlerFunc {  //1
       return func(c echo.Context) error {
           uri := c.Request().URL.String()
           log.Println("uri:" + uri)
           if uri != "/login.html" && uri != "/favicon.ico" {
               c.Redirect(http.StatusSeeOther, "login.html")
               return nil
           }
           return nil
       }
   })
   e.Use(session.Middleware(sessions.NewCookieStore([]byte("secret"))))
   e.GET("/aa", func(c echo.Context) error {   //2
       c.Redirect(http.StatusSeeOther, "login.html")
       return nil
   })

#2

You can try using an absolute path, like:

c.Redirect(http.StatusSeeOther, "/login.html")

And I think you should return the redirect call:

return c.Redirect(http.StatusSeeOther, "/login.html")