Angular 导航到带有角度路由器的部分
如何在Angular 2上导航到HTML的特定部分?我想导航如下:Angular 导航到带有角度路由器的部分,angular,angular-routing,Angular,Angular Routing,如何在Angular 2上导航到HTML的特定部分?我想导航如下: <a href="#first">First section</a></li> <a href="#second">Second section</a></li> <a href="#third">Third section</a></li> <section id="first"> Content.
<a href="#first">First section</a></li>
<a href="#second">Second section</a></li>
<a href="#third">Third section</a></li>
<section id="first">
Content...
</section
<section id="second">
Content...
</section>
<section id="third">
Content...
</section>
内容。。。
您需要将此添加到路由器中
const routerOptions: ExtraOptions = {
scrollPositionRestoration: 'enabled',
anchorScrolling: 'enabled',
scrollOffset: [0, 64],
};
@NgModule({
imports: [CommonModule, RouterModule.forRoot(routes, routerOptions)], //ExtraOptions
...
})
你的锚定标签应该是这样的
<a
[routerLink]="['/yourPageLink', params]" fragment="first}">First section</a>
应该可以。有什么问题吗?你在用路由器吗?@GünterZöchbauer我想用angular router,因为我正在将静态网页迁移到angular 2应用程序。我有一个导航栏组件,允许在应用程序中导航,但不起作用。路由器允许在另一个页面后面传递一个片段@GünterZöchbauer:我这样做了:链接到第一节
链接格式正确:localhost:4200/home#firstsection但不起作用。我自己没有尝试过。可能是个虫子。你能在一个扑克牌中复制吗?