绝对网址的行为类似于相对网址

时间:2015-08-20 10:02:06

标签: javascript angularjs url

我的应用程序页脚中有一堆链接(Angular 1.3.15)。

HTML

<section class="footer-projects">
        <div class="container">
            <div class="row">
                <section ng-repeat="area in ::links">
                    <h4 ng-bind="area.title"></h4>
                    <ul>
                        <li ng-repeat="project in ::area.projects">
                            <a href="{{project.url}}" ng-bind="project.name"></a>
                        </li>
                    </ul>
                </section>
            </div>
        </div>
    </section>

ng-repeat遍历此

js常数

'use strict';

require('./footer.module.js')
    .constant('FooterLinkConstants', [
        {
            title: 'Space',
            projects: [
                {
                    name: 'Galaxy Zoo',
                    url: 'http://www.galaxyzoo.org/'
                },
                {
                    name: 'Moon Zoo',
                    url: 'http://www.moonzoo.org/'
                },
                {
                    name: 'Solar Storm Watch',
                    url: 'http://www.solarstormwatch.com/'
                },
                {
                    name: 'Planet Hunters',
                    url: 'http://planethunters.org/'
                },
                {
                    name: 'Planet Four',
                    url: 'http://planetfour.org/'
                },
                {
                    name: 'Radio Galaxy Zoo',
                    url: 'http://radio.galaxyzoo.org/'
                },
                {
                    name: 'Stardate M83',
                    url: 'http://www.projectstardate.org/'
                },
                {
                    name: 'Disk Detective',
                    url: 'http://diskdetective.org/'
                }
            ]
        }
    ]);

这是我的指示

js指令

'use strict';

require('./footer.module.js')
    .directive('appFooter', appFooter);

// @ngInject
function appFooter($state, FooterLinkConstants) {
    var directive = {
        link: appFooterLink,
        restrict: 'A',
        replace: true,
        templateUrl: 'footer/footer.html'
    };
    return directive;

    function appFooterLink(scope) {
        scope.links = FooterLinkConstants;
        });
    }
}

一切都在开发中运作良好。但是,当我部署到远程服务器地址时,该地址会被添加到上面列表中的值之前。例如:

而不是

http://www.galaxyzoo.org/

我得到了

http://preview.zooniverse.org/folgerdemo/http://galaxyzoo.org/

您可以查看live example(只需检查页脚中的链接)

那么为什么会这样呢?

其他问题,如this,建议通过在地址中包含协议来使用绝对网址;我已经在做了。

我很确定我错过了一些明显的东西,但可以用一双新鲜的眼睛。

1 个答案:

答案 0 :(得分:0)

右。不幸的是,只有我能够知道答案 - 不是因为它显然很难,而是因为我没有在我的问题中提供所有信息。

我将我的应用程序构建为其他人的副产品。该应用程序使用Gulp作为任务管理器。

事实证明这一行

gulp.src(filename).pipe(replace(/(href=")(?![http|\/\/])/g, '$1' + prefix))

其中prefix值取决于所使用的AWS S3存储桶的类型,正在替换我的网址。

一旦我评论出这条线,事情就恢复了正常。

感谢那些为浪费你的时间而做出评论和道歉的人;)

相关问题