在角度应用中,在< a>中使用href不重新加载页面 [英] In an angular app, href in <a> doesn't reloads the page

查看:68
本文介绍了在角度应用中,在< a>中使用href不重新加载页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个有角度的应用程序

I have an angular app

<html ng-app='sampApp'>
</html>

我在应用程序内部有一个锚定链接.

I have an anchor link inside the app.

<a href='/user/profile'>Redirect here</a>

但是单击锚标记并不会重新加载页面.它只是进行ajax调用来呈现页面.

But the page is not getting reloaded on clicking the anchor tag. It just makes an ajax call to render the page.

推荐答案

除非使用html5模型,否则角度应以#开头的标准网址

Standard url used in angular start with #, unless you are using html5 model, so the anchor should be

< a href ='#/user/profile'>此处重定向</a>

如果要执行全页刷新或页面重定向,则需要停止Angular拦截路由.这是关于html链接重写的位置开发者指南状态

If you want to do full page refresh or page redirect, then you need to stop Angular from intercepting the route. Here is what location developer guide state regarding html link rewriting

包含目标元素的链接示例:< a href =""/ext/link?a = b"target ="_ self"> link</a>

到其他域的绝对链接.例如:< a href ="http://angularjs.org/"> link</a>

Absolute links that go to a different domain.Example: <a href="http://angularjs.org/">link</a>

以'/'开头的链接会在定义base时导致不同的基本路径.示例:< a href ="/not-my-base/link"> link</a>

Links starting with '/' that lead to a different base path when base is defined Example:<a href="/not-my-base/link">link</a>

这篇关于在角度应用中,在&lt; a&gt;中使用href不重新加载页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆