我有这样的路由器:
var mainmodule.config(function($routeProvider){
$routeProvider.when('/home',{
templateUrl:'src/home/home.html'
};
$routeProvider.when('/home/sports',{
templateUrl:'src/home/sports.html'
}
})
重定向效果很好。
问题是在我的主文件(index.html)中,头部声明中有以下css
:
<link rel="stylesheet" href="css/main.css"/>
如果我在localhost:8080/home
重新加载页面,则会正确加载样式。
但是,我在localhost:8080/home/sports
重新加载页面,因为他尝试加载localhost:8080/home/css/main.css
而不是localhost:8080/css/main.css
时未找到样式。
我是否错过了告诉routeProvider
维护原始css路径的配置?
此致
答案 0 :(得分:0)
使用相对于根路径:
<link rel="stylesheet" href="/css/main.css"/>