[英]How to navigate into sections with angular router?
如何在 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...
</section <section id="second">
Content...
</section>
<section id="third">
Content...
</section>
但使用 Angular 路由器。
你需要在你的路由器中添加这个
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>
文档请点击这里
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.