0

说,我正在浏览localhost/index.html#/view1,并且我有一个指向 的链接localhost/index.html。当我单击它时,通过它的 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 不要处理没有 hash 的 url?

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

4

1 回答 1

3

如果您询问忽略 url 链接的角度路由服务。见文档$location

在以下情况下,链接不会被重写;相反,浏览器将对原始链接执行完整的页面重新加载。

包含目标元素的链接

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

指向不同域的绝对链接

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

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

Example: <a href="/not-my-base/link">link</a>
于 2013-12-06T13:17:40.147 回答