UX: Do not redirect users if they are already on the site root

Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
Michael Mayer 2024-01-16 21:56:26 +01:00
parent 127b30dd31
commit d4317863f7
2 changed files with 15 additions and 6 deletions

View File

@ -2,7 +2,7 @@
<html lang="en" data-color-mode="dark" data-light-theme="light" data-dark-theme="dark" class="overflow-y-hidden">
<head>
<meta charset="utf-8">
<meta http-equiv="refresh" content="3; url=/">
{{if .redirect }}<meta http-equiv="refresh" content="3; url={{ .redirect }}">{{end}}
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">

View File

@ -39,12 +39,21 @@ var AbortNotFound = func(c *gin.Context) {
case gin.MIMEJSON:
c.JSON(http.StatusNotFound, gin.H{"error": i18n.Msg(i18n.ErrNotFound)})
default:
values := gin.H{
"signUp": gin.H{"message": config.MsgSponsor, "url": config.SignUpURL},
"config": conf.ClientPublic(),
"error": i18n.Msg(i18n.ErrNotFound),
"code": http.StatusNotFound,
var redirect string
// Redirect to site root if current path is different.
if root, path := conf.BaseUri("/"), c.Request.URL.Path; path != "" && path != root {
redirect = root
}
values := gin.H{
"signUp": gin.H{"message": config.MsgSponsor, "url": config.SignUpURL},
"config": conf.ClientPublic(),
"error": i18n.Msg(i18n.ErrNotFound),
"code": http.StatusNotFound,
"redirect": redirect,
}
c.HTML(http.StatusNotFound, "404.gohtml", values)
}