本文操作环境:windows7系统、react17.0.1、dell g3。
如何解决react link不跳转问题?
react router native:link点击不跳转
rn嵌入原生,出现点击touchableopacity组件内容没反应、不跳转的情况
// app.jsconst history = creatememoryhistory()<router history={ history }> <switch> <route path="/" component={ home }/> <route path="/test" component={ test } /> </switch></router>// home.js<view> <link to="/test"> <touchableopacity key={ text } style={ styles.wrapper }> <text style={ styles.text }>{ text }</text> </touchableopacity> </link></view>
1、关闭js remotely不知为何开了远程调试后导致touchableopacity失效。关闭后点击能看到touchableopacity效果,仍然不能跳转
2、给根路径route组件增加extra// app.js<router history={ history }> <switch> <route extra path="/" component={ home }/> // 增加extra <route path="/test" component={ test } /> </switch></router>
因为不熟悉rn开发,最初担心是使用了creatememoryhistory导致的,后来又担心页面跳转了但是被挡住之类的,思路一直偏了
最后老老实实到github上找了一个基础的项目,一点点找不同,才发现是这个被忽视的问题
原理其实很简单 https://www.cnblogs.com/superlizhao/p/9280122.html
我有这个问题是因为router4.x使用多层嵌套路由报了warning,调整之后反而暴露不认真读原理的问题,惭愧
3、将touchableopacity作为link组件的属性传入const linkparams = { pathname: '/star', state: { data: item },}<link to={ linkparams } component={ touchableopacity }> <item text={ item.text } index={ index }/></link>
<link>里面有<touchableopacity>会导致不跳转
推荐学习:《react视频教程》
以上就是如何解决react link不跳转问题的详细内容。
