我使用以下文章来学习如何向URL添加片段:
Angular2 Routing with Hashtag to page anchor
虽然片段被成功添加,但页面没有滚动到相应的锚点。我尝试在目标
上使用
name
和id
属性,但似乎都不起作用。
我正在使用 Angular 版本 2.0.0-rc.3 和路由器版本 3.0.0-alpha.6。
谢谢!
<a [routerLink]="[]" fragment="destination">Go TO DIV</a>
<div id='destination'>
<h2>Destination</h2>
</div>
两个元素之间有足够的空间,以便判断页面是否实际移动。
并且如之前所述,url正确地将#destination
添加到自身。
this._router.navigate( ['/somepath', id ], {fragment: 'test'});
示例在函数中更改它。 - jipson<a [routerLink]="['../currentroute']" fragment="destination">转到DIV</a>
。 - Günter Zöchbauer/docs
,所以我尝试使用<a [routerLink]="['../docs']" fragment="destination">前往DIV</a>
,它仍会生成正确的URL。然而,它仍然没有移动。 - jipson