The Fileserver Example Code:
r.Get(path, func(w http.ResponseWriter, r *http.Request) {
rctx := chi.RouteContext(r.Context()) // sets the route context
pathPrefix := strings.TrimSuffix(rctx.RoutePattern(), "/*") // this displays the path
fmt.Printf(pathPrefix + "\n")
fs := http.StripPrefix(pathPrefix, http.FileServer(root))
fs.ServeHTTP(w, r)
})
When I run the server, it works When I click on router-links from the SPA, it works When I type a link in from the browser and not use the SPA, it doesnt work and returns 404
How do I bypass this and serve the files instead?