给该链接对应的模块加ref,拿到该模块的ref后,使用scrollIntoView(),即滚动到该模块
或者也可以使用ref拿到该模块,然后用getBoundingClientRect()获取元素位置,这个方法没有参数
getBoundingClientRect()用于获得页面中某个元素的左,上,右和下分别相对浏览器视窗的位置。 getBoundingClientRect()是DOM元素到浏览器可视范围的距离(不包含文档卷起的部分)
假设用getBoundingClientRect()拿到左边的距离为5,则使用scrollTo
div.scrollTo({ left: -5, behavior: “smooth” });