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

How to use two hashPrefix in and AngularJS application?

本文关键字:hashPrefix 两个 AngularJS 应用程序      更新时间:2023-09-26

我正在尝试对我的SPA SEO友好,目前它的链接形式为#/path/page,我正在尝试移动到#/path/page遗憾的是,该网站目前正在生产中,并且已经在社交网站上共享了,所以我试图保留旧链接(#/path/page)。

有没有一种方法可以重定向此流量,或者有任何变通方法可以同时使用哈希前缀#和#!?

我找到了一个简单的解决方案,不涉及AngularJS,只涉及javascript:

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