저는 여기서 만든 메인페이지에서 about 페이지로 이동할 생각입니다.
{{define "footer.html"}}
</div>
</body>
</html>
{{end}}
{{define "header.html"}}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text">
<title></title>
</head>
<body>
<div class="container">
{{end}}
{{template "header.html"}}
<h1 class="title">{{.title}}</h1>
<a href="{{.url}}">about으로 이동</a>
{{template "footer.html"}}
{{template "header.html"}}
<h1>about Page</h1>
<p>{{ .content}}</p>
{{template "footer.html"}}
package main
import (
"fmt"
"github.com/gin-gonic/gin"
"net/http"
)
func setRouter(router *gin.Engine) {
router.GET("/", func(c *gin.Context) {
c.HTML(http.StatusOK, "index.html", gin.H{
"title": "메인페이지",
"url": "/about",
})
})
router.GET("/about", func(c *gin.Context) {
c.HTML(http.StatusOK, "about.html", gin.H{
"content": "내용",
})
})
}
func main() {
router := gin.Default()
router.LoadHTMLGlob("templates/*.html")
setRouter(router)
_ = router.Run(":8080")
}
이제 링크가 생겼습니다.
짠...! 링크를 누르면 about페이지로 이동할수 있습니다.