Reputation: 3728
I'm trying to use react-native for a web\app. I would like to create a simple link to a different screen, but using urls and not elements.
I managed to get it to work with 2 annoying caviats:
window.location.href
and Linking.getInitialURL()
does return the full linkLinking.openURL
only opens new tabs, and I would like it to stay in the same tab when clicking.Screen 1:
import { Linking, StyleSheet, Text, View } from "react-native";
import React from "react";
import WebView from "react-native-webview";
const Infromation = () => {
const uri = "links";
return (
<Text
onPress={() => {
Linking.openURL("feed");
}}
>
AboutReact
</Text>
);
};
export default Infromation;
const styles = StyleSheet.create({});
That link opens the feed screen, but in a new tab and url tail not showing:
Feed screen code:
import {
KeyboardAvoidingView,
Linking,
StyleSheet,
Text,
TextInput,
TouchableOpacity,
View,
} from "react-native";
import React, { useEffect } from "react";
const Feed = () => {
const url = new URL(window.location.href);
Linking.getInitialURL().then((url) => {
console.log(url);
});
return (
<Text>{url.href}</Text>
);
};
export default Feed;
Upvotes: 2
Views: 1645
Reputation: 11987
You can pass second parameter to openURL()
and pass _self
as the value
Something like this
`openURL("your url here", "_self")`
Upvotes: 0