阵营路由器browserHistory推动和锚
当使用browserHistory从阵营路由器4以编程方式导航到一个锚:阵营路由器browserHistory推动和锚
import { withRouter } from 'react-router-dom' ... 
props.history.push('#blah') 
我可以看到散列在地址栏中改变,但页面不滚动到相关的主播。我已经用标准的<a href="#blah">Blah</a>检查过了,这工作正常。任何想法我做错了什么?谢谢:)
UPDATE 
 刚才检查和<Link to="#blah">Blah</Link>不工作要么...我假设反应Links工作中使用的历史对象吗?
回答:
经过一番调查后,我决定添加一个函数来处理componentDidUpdate生命周期事件:
componentDidUpdate: props => {     const selected = props.history.location.hash 
    if(selected && selected.length > 0) { 
    const elem = document.getElementById(selected) 
    elem && elem.scrollIntoView() 
    } 
} 
这解决了
以上是 阵营路由器browserHistory推动和锚 的全部内容, 来源链接: utcz.com/qa/258859.html

