找不到react-scroll目标元素

时间:2019-08-13 20:59:28

标签: reactjs

我有一个for (let key in this.chartData) { emptyArr.push({ name: this.chartData[key].project, data: Object.values(this.chartData[key].sum), }); } React组件和一个[ { "name": "Project 1", "data": [8, 16, 8, 8, 21, 4, 5, 2, 0, 2, 5, /*Need a "0" here*/] }, { "name": "Project 2", "data": [9, 18, 9, 9, 17, 5, 2, 4, /*Need 4 more 0's here*/] }, { "name": "Project 3", "data": [2, 2, 5, 2, 0, 10, 45, 21, 3, 2, 17, 16] } ] 组件,单击该组件需要向下滚动到Navbar组件。我已经实现了Link,但是,当我单击Section组件时,在浏览器控制台中得到了react-scroll

导航栏组件:

Link

还有App.js文件:

target element not found

我使用this repo作为参考,但是,事情没用。我在这里错过了什么?

1 个答案:

答案 0 :(得分:0)

我已经在SectionOne组件内部实现了div

<div id="section-one-wrapper">Section One content...</div>

,然后在Link组件中指定该ID:

<Link to="section-one-wrapper" activeClass="active" spy={true} smooth={true}>
    Section 1
</Link>

它奏效了。