简体   繁体   English

如何在和AngularJS应用程序中使用两个hashPrefix?

[英]How to use two hashPrefix in and AngularJS application?

I'm trying to do my SPA SEO-friendly and currently it has the links in the form #/path/page and i'm trying to move to #!/path/page sadly the site is currently in production and it has been shared already on socials, so i'm trying to keep available the old links (#/path/page). 我正在尝试对SPA SEO进行友好处理,目前它具有#/ path / page形式的链接,而我正在尝试移至#!/ path / page,可悲的是该站点当前正在生产中,并且已经已经在社交网站上共享了,所以我试图保持可用的旧链接(#/ path / page)。

Is there a way to redirect this traffic or any workaround to have both hash-prefix working, # and #!? 有没有一种方法可以重定向此流量或任何变通方法,以使#和#!哈希前缀都起作用?

I found an easy solution, not involving AngularJS only javascript: 我找到了一个简单的解决方案,不只涉及AngularJS javascript:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM