在HTML文件中调用它后,我将React应用程序与Webpack捆绑在一起.但是,当我使用Golang和html/template查看HTML文件时,它会出错.
我的HTML文件:index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Note App</title>
</head>
<body>
<div id="root"></div>
<script src="public/bundle.js"></script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我的Golang文件:index.go
package main
import (
"net/http"
"html/template"
"path/filepath"
)
func handle(w http.ResponseWriter, r *http.Request) {
fp := filepath.Join("views", "index.html")
t := template.Must(template.ParseFiles(fp))
t.Execute(w, nil)
}
func main() {
http.HandleFunc("/", handle)
http.ListenAndServe(":8080", nil)
}
Run Code Online (Sandbox Code Playgroud)