Html可以通过hash(#) url跳转到指定位置,例如:
index.html:
<div id='loc_a'>
loc_a
</div>
<div id='loc_b'>
loc_b
</div>
<div id='loc_c'>
loc_c
</div>如果您想要直接滑动到position loc_c,您可以使用以下网址:http:\\127.0.0.1:4200\index.html#loc_c
但是,无论指定的元素是在主组件还是子路由中,angular路由器都不能识别散列URL。
路由器示例:
{
path: '', component: mainComponent,
children: [
{path: '', component: childrenComponent},
]
}发布于 2020-02-06 18:14:56
您可以尝试使用window.scrollTo
const ele = document.getElementById(elementId);
if (ele) {
window.scrollTo(ele.offsetLeft, ele.offsetTop);
}https://stackoverflow.com/questions/60092361
复制相似问题