-
Notifications
You must be signed in to change notification settings - Fork 464
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[QUESTION] - How to redirect to different url in middleware? #414
Comments
cc @zstone12 |
@li-jin-gou In middleware whatever I put, |
func WebAuth(redirectTo string) app.HandlerFunc {
if redirectTo == "" {
redirectTo = "/"
}
return func(c context.Context, ctx *app.RequestContext) {
if _, ok := ctx.Get("user"); !ok {
ctx.Redirect(consts.StatusFound, []byte(redirectTo))
ctx.Abort()
}
ctx.Next(c)
}
} Should use |
refer to https://www.cloudwego.io/docs/hertz/tutorials/basic-feature/middleware/ |
Ah! got it. So wouldn't it be good if |
Thanks for explanation. I was just wondering any use case where I would only call |
I'm trying to redirect to different internal url in middleware, but I'm not redirected. This is the code I tried.
The code enters the middleware and inside the if for redirection when tried to visit
"/"
, but it's not redirecting to"/foo"
and ends up with"Home"
responseExpected Result:
The page should have redirected to
"/foo"
instead of going inside"/"
Please suggest what am I doing wrong
The text was updated successfully, but these errors were encountered: