gpt4 book ai didi

javascript - 避免使用 ng-route 路由无哈希 url

转载 作者:行者123 更新时间:2023-11-28 20:08:00 27 4
gpt4 key购买 nike

假设,我正在浏览 localhost/index.html#/view1,并且有一个指向 localhost/index.html 的链接。当我单击它时,Angular 通过其 ng-route 模块对其进行处理,并将其纳入我的重定向子句中。

这是路由配置的摘录:

$routeProvider
.when( "/view1", route1 )
.otherwise({redirectTo:'/view1'}); // localhost/index.html clicks fall here

我可以使用 ng-click,然后使用 location.href 进行 javascript 重定向,但这不是一个理想的解决方案,因为我会丢失 href 链接(SEO、书签、选项卡)。

tl;博士

如何告诉 angularJs ng-route 不要处理没有哈希值的网址?

编辑:我不使用 html5 模式,也不打算使用它。

最佳答案

如果您询问有关 Angular 路由服务的信息,请忽略 url 链接。请参阅 $location

的文档

In cases like the following, links are not rewritten; instead, the browser will perform a full page reload to the original link.

包含目标元素的链接

Example: <a href="/ext/link?a=b" target="_self">link</a>

转到不同域的绝对链接

Example: <a href="http://angularjs.org/">link</a>

以“/”开头的链接在定义基本路径时会导致不同的基本路径

Example: <a href="/not-my-base/link">link</a>

关于javascript - 避免使用 ng-route 路由无哈希 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20424647/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com