具体过程就不说,是搞这个的自然会动,只把关键代码贴出来。
// landv.cnblogs.com
//没有授权转载我的内容,再不加链接,呵呵
package main import ( "routers" "github.com/astaxie/beego" "github.com/astaxie/beego/context" "net/http" "strings" ) func main() { ignoreStaticPath() beego.Run() } func ignoreStaticPath() { beego.InsertFilter("/",beego.BeforeRouter,TransparentStatic) beego.InsertFilter("/*",beego.BeforeRouter,TransparentStatic) } func TransparentStatic(ctx *context.Context){ orpath := ctx.Request.URL.Path beego.Info("request url:",orpath) //如果请求url包含api字段,说明指令应该取消静态资源重定向 if strings.Index(orpath,"api") >= 0{ return } http.ServeFile(ctx.ResponseWriter,ctx.Request,"static/"+ctx.Request.URL.Path)//vue编译通过的内容放在这里 }