在配置阶段添加一个哈希preFIX如果缺少

在配置阶段添加一个哈希preFIX如果缺少

本文介绍了在配置阶段添加一个哈希preFIX如果缺少的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在在我的Angularjs基于web的应用程序集成幻象。

I am now integrating phantom in my Angularjs-based web application.

的美好的文章说,我应该叫 $ locationProvider.hash preFIX()方法来设置preFIX为'!从SEO的原因(让爬虫拦截的URL _escaped_fragment 组件)。

This fine article says that I should call the $locationProvider.hashPrefix() method to set the prefix to '!' from SEO reasons(allow crawlers to intercept the _escaped_fragment component of the URL).

问题是我没有的,虽然早期,有些我的网址看起来如下:
#/家

The problem is that I haven't though of the earlier, and some of my URLs look as following:#/home.

我虽然也许有,我可以植入这种方式'!焦炭引入URL的乞讨编程(如果它已不存在),在APP的配置功能,而无需手动编辑了大量的标记。

I though perhaps there is a way that I can implant this '!' char into the begging of the URL programmatically(in case it is not already there) at the config function of the APP, instead having to edit a lot of markup manually.

推荐答案

我有类似的问题,手动(搜索/替换)通过所有的链接去和固定它们。

I've had similar problem and manually (search/replace) went through all the links and fixed them.

其他的问题,我是在外部网站使用了旧格式,即

代替新格式

The other problem I had was the external sites were using the old format i.e.http://plinkplink.net/#/event/3instead of the new formathttp://plinkplink.net/#!/event/3

我也为修复程序不严格来说angularjs地道,但它的工作。我已经添加了这个剧本到我的网页的标题。它只是用重定向页面#与#页!:

The fix I did for that is not strictly speaking angularjs idiomatic but it does the job. I've added this script to the header of my page. It simply redirects pages with # to pages with #!:

    <script>
        var loc = window.location.href
        if (loc.indexOf("#") != -1 &&  loc.indexOf("#!") == -1 ){
            window.location.href = loc.replace("#", "#!");
        }
    </script>

我希望它能帮助。

I hope it helps.

这篇关于在配置阶段添加一个哈希preFIX如果缺少的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 17:43