Skip to content

Commit

Permalink
refactor: use a route for htmx
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Brereton authored and Tom Brereton committed Jan 10, 2024
1 parent 067f0b3 commit ed70ebc
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion internal/routes/htmx.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
func Htmx(t *template.Template) *chi.Mux {
r := chi.NewRouter()

r.Get("/", func(w http.ResponseWriter, r *http.Request) {
r.Get("/clicked", func(w http.ResponseWriter, r *http.Request) {
err := t.ExecuteTemplate(w, "htmx-demo.html", nil)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
Expand Down
2 changes: 1 addition & 1 deletion internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (s *Server) MountMiddleware() {
func (s *Server) MountPageHandlers() {
s.Router.NotFound(routes.NotFound(s.Templates))
s.Router.Mount("/", routes.LandingPage(s.Templates))
s.Router.Mount("/clicked", routes.Htmx(s.Templates))
s.Router.Mount("/htmx", routes.Htmx(s.Templates))
}

func (s *Server) MountStaticFiles() {
Expand Down
2 changes: 1 addition & 1 deletion templates/landing.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ <h1 id="hello" class="text-3xl font-bold text-blue-500 underline">
Hello, {{ .Name }}!
</h1>

<button hx-get="/clicked" hx-swap="outerHTML" class="m-2 p-2 rounded-lg bg-slate-800 text-white">
<button hx-get="/htmx/clicked" hx-swap="outerHTML" class="m-2 p-2 rounded-lg bg-slate-800 text-white">
Click Me
</button>
</body>
Expand Down

0 comments on commit ed70ebc

Please sign in to comment.