【问题标题】:relative href path goes wrong in angularjs with html5mode使用html5mode的angularjs中的相对href路径出错
【发布时间】:2015-03-02 10:16:29
【问题描述】:

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

情况:

index.js

   $locationProvider
        .html5Mode(true);

index.html

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

问题

当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

亲切的问候

【问题讨论】:

    标签: javascript angularjs html


    【解决方案1】:

    编辑: 刚刚发现如果我把标签 before 注入样式它会起作用......我的 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>
    

    上一个答案:

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

    之前:

    var injectOptions = {
      ignorePath: [options.src, options.tmp + '/serve'],
      addRootSlash: false
    };
    

    之后:

    var injectOptions = {
      ignorePath: [options.src, options.tmp + '/serve']
    };
    

    【讨论】:

    • 刚收到这个问题,第一次发帖解决了我的问题。谢谢大佬。
    • 我绝不会尝试将基本标签向上移动!感谢您发布解决方案
    猜你喜欢
    • 2015-02-25
    • 2014-11-21
    • 2021-06-17
    • 2018-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-24
    • 1970-01-01
    相关资源
    最近更新 更多