【问题标题】:Jumping to specific location in a page in react在反应中跳转到页面中的特定位置
【发布时间】:2018-08-02 05:10:14
【问题描述】:

单击按钮时,我需要转到页面上的特定行。如何使用 react-router 来完成。我有:

<Grid xs={3}>    
  <Button>heading</Button>
  <Button>Heading2</Button>
</Grid>
<Grid xs={3}>    
  <h1>heading</h1>
  <p>Paragraph</p>
  <h2>Heading2</h2>
  <p>Paragraph2</p>
</Grid>

当点击标题按钮时,它应该跳转到第二个网格中的相关位置。怎么做。我也提到了How to use react-router to jump to specific location in the page

【问题讨论】:

  • 我已经更新了我的答案。检查一下

标签: reactjs react-router page-jump


【解决方案1】:

将您的 Link 组件包装在 MUI Button 中,并为您的第二个网格定义一个 id 属性,例如 gridWrapper

<Grid xs={3}>    
  <Button component={Link} to="#gridWrapper">heading</Button>
  <Button>Heading2</Button>
</Grid>
<Grid xs={3} id="gridWrapper">    
  <h1>heading</h1>
  <p>Paragraph</p>
  <h2>Heading2</h2>
  <p>Paragraph2</p>
</Grid> 

【讨论】:

  • 我们需要在 react router 中定义一些东西吗?
  • 点击按钮,会改变url,但不会重定向
猜你喜欢
  • 1970-01-01
  • 2015-04-19
  • 2015-03-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多