我正在使用CHI路由,并提供如下文件:
fileServer := http.FileServer(http.Dir("./static/"))
mux.Handle("/static/*", http.StripPrefix("/static", fileServer))
在html文件中:
<img src="./static/images/img.png" />
一切都运行得很好,当判断img.png的路径为http://localhost:8080/static/images/img.png
时,这是很好的…但当用户访问个人资料时...
mux.Route("/user", func(mux chi.Router) {
mux.Use(Auth)
mux.Get("/profile", handlers.Repo.ProfileGet) // path: /user/profile
})
在用户登录并访问该路径http://localhost:8080/user/profile
之后,图像不会出现(因为路径已经改变)...当我判断图像路径时,我发现:http://localhost:8080/user/static/images/img.png
而不是http://localhost:8080/static/images/img.png
如何解决此问题?