使用html5mode在angularjs中出现相对href路径错误

Dan*_*e A 4 javascript html5 angularjs

我正在使用AngularJS来处理我的URL,并打开了html5mode.我也在使用gulp-angular生成器来构建项目.

情况:

index.js

   $locationProvider
        .html5Mode(true);
Run Code Online (Sandbox Code Playgroud)

的index.html

<!-- build:css({.tmp,src}) styles/app.css -->
<!-- inject:css -->
<link rel="stylesheet" href="app/index.css">
<!-- endinject -->
<!-- endbuild -->
<base href="/" />
Run Code Online (Sandbox Code Playgroud)

问题

当url是example.com/somepage,index.css来自example.com/app/index.css但当url是example.com/somepage/somedeeperpage,并且我刷新页面时,index.css来自example.com/somepage/app/index.css

我希望能够在angular-gulp生成器中默认使用相对路径.

我是否必须在gulpfile中更改为基本标记或index.css rel路径?

奇怪的是,相对路径可以很好地找到index.js

亲切的问候

Nan*_*com 5

编辑:只是想通了如果我在注入样式之前放置标签就行了......我的index.html现在看起来像这样:

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <base href="/">
    <!-- build:css({.tmp/serve,src}) styles/app.css -->
    <!-- inject:css -->
    <!-- endinject -->
    <!-- endbuild -->
</head>
Run Code Online (Sandbox Code Playgroud)

上一个答案:

有同样的问题,通过添加我的index.html文件和更改gulp/inject.js中的gulp-inject配置来完成这项工作:

之前:

var injectOptions = {
  ignorePath: [options.src, options.tmp + '/serve'],
  addRootSlash: false
};
Run Code Online (Sandbox Code Playgroud)

之后:

var injectOptions = {
  ignorePath: [options.src, options.tmp + '/serve']
};
Run Code Online (Sandbox Code Playgroud)