beego多级路由导致页面不能正常加载css样式

YoungBlood · 2017-03-17 06:11:59 · 4774 次点击 · 大约8小时之前 开始浏览    置顶
这是一个创建于 2017-03-17 06:11:59 的主题,其中的信息可能已经有所发展或是发生改变。

(1)路由设置:beego.Router("/index",&controller{}) (2)controller的Get()方法:this.TplName="index.html" (3)其中index.html位于views文件夹下,引用了位于static文件夹下的css,"./static/css/xxxxx; 此时访问/index路径能正常加载css显示index.html页面。 (4)如果把路由设置成beego.Router("admin/index",&controller{}),其他不变,访问admin/index时则不能正常显示index.html页面. (5)检查页面元素时发现index.html页面加载的css路径位于admin/static/css/xxxxx,这不是我想要的路径,这种情况怎么解决呢?


有疑问加站长微信联系(非本文作者)

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

4774 次点击  
加入收藏 微博
7 回复  |  直到 2017-03-17 07:20:26
xiaochuan
xiaochuan · #1 · 8年之前

这个似乎 跟上面设置的路径没关系啊。 你看看 staticRouter

xiaochuan
xiaochuan · #2 · 8年之前

SetStaticPath

YoungBlood
YoungBlood · #3 · 8年之前
xiaochuanxiaochuan #2 回复

SetStaticPath

我刚实践了一下SetStaticPath,也没有用,设置:beego.SetStaticPath("/admin", "static")

xiaochuan
xiaochuan · #4 · 8年之前
YoungBloodYoungBlood #3 回复

#2楼 @xiaochuan 我刚实践了一下SetStaticPath,也没有用,设置:beego.SetStaticPath("/admin", "static")

我看一下你这边的 view 怎么引用的。

YoungBlood
YoungBlood · #5 · 8年之前
xiaochuanxiaochuan #4 回复

#3楼 @YoungBlood 我看一下你这边的 view 怎么引用的。

view/admin/index.html,index.html中的引用是:"././static/css/xxxxx.css" controller中的是this.TplName="admin/index.html"

xiaochuan
xiaochuan · #6 · 8年之前
YoungBloodYoungBlood #5 回复

#4楼 @xiaochuan view/admin/index.html,index.html中的引用是:"././static/css/xxxxx.css" controller中的是this.TplName="admin/index.html"

怪不得。不是那么引入的哈。你找找对应的view 手册看一下就知道了。

YoungBlood
YoungBlood · #7 · 8年之前
xiaochuanxiaochuan #6 回复

#5楼 @YoungBlood 怪不得。不是那么引入的哈。你找找对应的view 手册看一下就知道了。

ok,已成功解决,谢谢前辈指点!

添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传