具體過程就不說,是搞這個的自然會動,只把關鍵代碼貼出來。
beego和vue前后端分離開發,beego承載vue前端分離頁面部署
// landv.cnblogs.com //沒有授權轉載我的內容,再不加鏈接,呵呵 package main import ( _ "aa/routers" "github.com/astaxie/beego/context" "net/http" "strings" "github.com/astaxie/beego" ) func main() { ignoreStaticPath() beego.Run() } func ignoreStaticPath() { //pattern 路由規則,可以根據一定的規則進行路由,如果你全匹配可以用"*" // beego.InsertFilter("*",beego.BeforeRouter,TransparentStatic) beego.InsertFilter("/",beego.BeforeRouter,TransparentStatic) beego.InsertFilter("/*",beego.BeforeRouter,TransparentStatic) } func TransparentStatic(ctx *context.Context) { orpath := ctx.Request.URL.Path beego.Debug("request url:",orpath) //如果請求url還有api字段,說明指令應該取消靜態資源路徑重定向 if strings.Index(orpath,"api")>=0{ return } if strings.Index(orpath,"test")>=0{ return } http.ServeFile(ctx.ResponseWriter,ctx.Request,"static/lan/dist/"+ctx.Request.URL.Path) }