summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-08-07 16:04:11 +0200
committerThomas Voss <mail@thomasvoss.com> 2024-08-07 16:04:11 +0200
commit6332cce84ceabf90d8c42167148f41d98d0c28b9 (patch)
tree2dfd2bc0c5a82285b81c5c1e054c86cf51f6b1f1
parent257d58f0a212df249c19e2159cd6871c4154fda3 (diff)
Properly redirect the user after language selection
-rw-r--r--main.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/main.go b/main.go
index e0c88ef..2cc3b41 100644
--- a/main.go
+++ b/main.go
@@ -1,6 +1,7 @@
package main
import (
+ "cmp"
"errors"
"flag"
"fmt"
@@ -52,6 +53,16 @@ func finalHandler(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNotFound)
fmt.Fprintln(w, p.T("Page not found"))
} else {
+ /* When a user clicks on the language button to be taken to the
+ language selection page, we need to set a redirect cookie so
+ that after selecting a language they are taken back to the
+ original page they came from. */
+ if path == "/language" {
+ http.SetCookie(w, &http.Cookie{
+ Name: "redirect",
+ Value: cmp.Or(r.Referer(), "/"),
+ })
+ }
templates.Root(nil, c).Render(r.Context(), w)
}
}