rn項目的路由使用link標籤可以成功跳轉
const linkParams = {
pathname: '/star',
state: { data: item },
}
<Link to={ linkParams } component={ TouchableOpacity }>
<Item text={ item.text } index={ index }/>
</Link>
但是在rn to web時,這種寫法的link會失效不跳轉。因此使用history.push代替<Link>標籤,時rn和web環境時都可以跳轉
const linkParams = {
pathname: '/star',
state: { data: item },
}
<TouchableOpacity onPress={ ()=>{ this.props.history.push(linkParams) } }>
<Item text={ item.text } index={ index }/>
</TouchableOpacity>
history.push的跳轉原理和<Link>是一樣的