在当前窗口中打开链接react-native链接

问题描述 投票:0回答:1

我正在尝试将react-native用于网络应用程序。我想创建一个到不同屏幕的简单链接,但使用 url 而不是元素。

我设法让它与 2 个恼人的空洞一起工作:

  1. 网址的尾部显示一秒钟,然后从浏览器网址输入中消失(即使
    window.location.href
    Linking.getInitialURL()
    确实返回完整链接
  2. Linking.openURL
    仅打开新选项卡,我希望单击时它保持在同一个选项卡中。

屏幕 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({});

该链接会打开 feed 屏幕,但在新选项卡中且 url 尾部未显示: enter image description here

提要屏幕代码:

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;
react-native react-navigation deep-linking react-native-linking
1个回答
0
投票

您可以将第二个参数传递给

openURL()
并将
_self
作为值传递

类似这样的事情

`openURL("your url here", "_self")`
© www.soinside.com 2019 - 2024. All rights reserved.