Angular 2 路由器、href 链接和不需要的页面刷新 [英] Angular 2 Router, href links and unwanted page refresh
问题描述
我目前正在试验 angular2 (beta1),但我对新路由器有点困惑.
i am currently experimenting with angular2 (beta1) and i'm a bit puzzled about the new router.
通过 router.navigate 导航就像一个魅力,尝试通过一个注册路由的正常链接来刷新页面.这当然发生在 PathLocationStrategy 中,因为 HashLocationStrategy 按预期工作.
Navigating via router.navigate works like a charm, while trying to do that via a normal link to a registered route refreshes the page. This happens with PathLocationStrategy of course, as HashLocationStrategy works as expected.
这是错误还是正常行为?
Is this a bug or the normal behaviour?
TIA
推荐答案
另见https://angular.io/guide/ajs-quick-reference#ng-href
您可以将事件侦听器添加到 <a href=...
元素或父元素并调用 router.navigate...
和 事件.preventDefault()
.
You could add event listeners to the <a href=...
elements or a parent and call router.navigate...
and event.preventDefault()
.
这篇关于Angular 2 路由器、href 链接和不需要的页面刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!