AngularJS / Gulp / Router:更改路由时找不到CSS

时间:2016-10-13 10:24:52

标签: css angularjs gulp angular-routing

我有这样的路由器:

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路径的配置?

此致

1 个答案:

答案 0 :(得分:0)

使用相对于根路径:

<link rel="stylesheet" href="/css/main.css"/>