Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.4k views
in Technique[技术] by (71.8m points)

React-Router中的Link,路由地址不变的时候如何重载组件?

如当前路由地址为:http://localhost:8585/#/book
页面中有个<Link to="/book?id=1">《前端从入门到放弃》</Link>

如何在点击Link的时候让页面重载?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

如果你用的react15.x的版本 可以参考react-router url参数更新
componentWillReceiveProps去控制

如果用的react16.x的版本 我觉得可以用useRef+useEffect去控制
useRef记录你旧的参数 useEffect去比对新的参数和旧的参数是不是有区别 再去页面重载

还是页面分开比较好 换个url去做新的事情


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...