我是靠谱客的博主 优美皮带,这篇文章主要介绍如何解决react link不跳转问题,现在分享给大家,希望可以做个参考。

本文操作环境:Windows7系统、react17.0.1、Dell G3。

如何解决react link不跳转问题?

react router native:link点击不跳转

rn嵌入原生,出现点击TouchableOpacity组件内容没反应、不跳转的情况

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// App.js const 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

复制代码
1
2
3
4
5
6
7
// 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组件的属性传入

复制代码
1
2
3
4
5
6
7
8
const linkParams = { pathname: '/star', state: { data: item }, } <Link to={ linkParams } component={ TouchableOpacity }> <Item text={ item.text } index={ index }/> </Link>
登录后复制

<link>里面有<TouchableOpacity>会导致不跳转

推荐学习:《react视频教程》

以上就是如何解决react link不跳转问题的详细内容,更多请关注靠谱客其它相关文章!

最后

以上就是优美皮带最近收集整理的关于如何解决react link不跳转问题的全部内容,更多相关如何解决react内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(78)

评论列表共有 0 条评论

立即
投稿
返回
顶部