我正在使用以下代码来为 Angular 应用提供服务。
package main
import (
"github.com/gorilla/mux"
"log"
"net/http"
)
func main() {
r := mux.NewRouter()
r.PathPrefix("/portals/").Handler(http.StripPrefix("/portals/", http.FileServer(http.Dir("./portals/"))))
r.PathPrefix("/dependencies/").Handler(http.StripPrefix("/dependencies/", http.FileServer(http.Dir("./dependencies/"))))
r.HandleFunc("/registeruser", UserRegistrationHandler)
r.HandleFunc("/deleteuser/{username}", DeleteUserHandler)
http.Handle("/", r)
log.Println("Listening...")
http.ListenAndServe(":8000", r)
}
如果我导航到 http://localhost:8000/portals/它能够使用所有依赖项正确呈现站点。但是 http://localhost:8000/portals失败并返回 404 Not Found。
同样,如果我导航到 http://localhost:8000/portals/#login它按预期工作。但是如果我导航到 http://localhost:8000/portals/login它给出 404。
我注意到的另一件事是 http://localhost:8000/portals/login如果我通过应用程序内的链接(例如登录链接)导航到它,则 url 有效。但是,如果我在浏览器中键入 url 并按回车键,它会显示 404。
这里遗漏了什么?我是否错误地处理了静态内容?
最佳答案
你需要在angularjs中启用html5mode
关于angularjs - 服务 angularjs 路由 go-lang,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32534499/