Angular Js - 单击同一链接不会重新加载页面

时间:2021-01-06 21:12:22

Recently we started using Angular js and as result of using Angular js, we came across few issues.

最近我们开始使用Angular js,并且由于使用Angular js,我们遇到了一些问题。

  1. Href doesn't reload the same page on clicking, I have found one solution online but I am not sure if this is a good idea to use or not. Is there any way we can handle it from Angular js side?
  2. Href不会在点击时重新加载同一页面,我在网上找到了一个解决方案,但我不确定这是否是一个好主意使用与否。我们有什么方法可以从Angular js方面处理它吗?

(In an angular app, href in <a> doesn't reloads the page)

(在角度应用程序中,中的href不会重新加载页面)

  1. Anchor links are not working. Previously only single # used to work and scroll was happening. Now it need the below format to scroll.
  2. 锚链接不起作用。以前只有单#用于工作和滚动正在发生。现在需要以下格式滚动。

http://www.test.com/about/#/#2308592

I have a large website, I can't go and change all anchor to above format. Same way I can't put target="_self" to all my Href. Let me know if we have a solution from Angular Js side.

我有一个大型网站,我不能去改变所有锚到以上格式。同样的方法我不能把target =“_ self”放到我所有的Href中。如果我们从Angular Js方面获得解决方案,请告诉我。

1 个解决方案

#1


0  

You could disable the default anchor behavior by using something from this answer -

您可以使用此答案中的内容禁用默认锚定行为 -

How to preventDefault on anchor tags?

如何防止锚标签的默认?

And then control reload using -

然后使用 - 控制重载

$location.path(incomingPath);
$route.reload()

where you can get the 'incomingPath' for $location from the anchor's click event.

您可以从锚点击事件中获取$ location的'incomingPath'。

I do not think there's any other way apart from this without having to change the individual anchor tags to be Angular friendly.

我不认为除了这个之外还有其他任何方式,而不必将单个锚标签更改为Angular友好。

#1


0  

You could disable the default anchor behavior by using something from this answer -

您可以使用此答案中的内容禁用默认锚定行为 -

How to preventDefault on anchor tags?

如何防止锚标签的默认?

And then control reload using -

然后使用 - 控制重载

$location.path(incomingPath);
$route.reload()

where you can get the 'incomingPath' for $location from the anchor's click event.

您可以从锚点击事件中获取$ location的'incomingPath'。

I do not think there's any other way apart from this without having to change the individual anchor tags to be Angular friendly.

我不认为除了这个之外还有其他任何方式,而不必将单个锚标签更改为Angular友好。