构建后具有反应导航问题深层链接的expo托管工作流

问题描述

在我的本机项目中,我遇到了expo + react-navigation进行深度链接的问题。

我阅读了本文档https://reactnavigation.org/docs/deep-linking/

如果我尝试使用adb之类的调用方式,则深层链接在我的开发模式(仿真器)中运行良好

adb shell am start -d "exp://192.168.100.96:19000/--/LoginPage

adb shell am start -d "exp://192.168.100.96:19000/--/Details

页面可以更改,但是构建后,我只能打开主页。

那是我的代码

app.json

{
  "expo": {
    "name": "exampleapp","scheme": "exampleapp",...
}

我的导航


import * as React from 'react';
import { View,Text,StyleSheet,Button } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
import * as Linking from 'expo-linking';

const prefix = Linking.makeUrl('/');

function HomeScreen({ navigation}) {
    return (
        <View style={{ flex: 1,alignItems: 'center',justifyContent: 'center' }}>
            <Text>Home Screen</Text>
            <Button
                title="Go to Details"
                onPress={() => navigation.navigate('Details')}
            />
        </View>
    );
}

function DetailsScreen() {
    return (
        <View style={{ flex: 1,justifyContent: 'center' }}>
            <Text>Details Screen</Text>
        </View>
    );
}

const Stack = createStackNavigator();

function App() {
    const linking = {
        prefixes: [prefix],config: {
            screens: {
                Home: 'home',Details: 'detail',},};
    
    return (
        <NavigationContainer linking={linking} >
            <Stack.Navigator initialRouteName="Home">
                <Stack.Screen name="Home" component={HomeScreen} />
                <Stack.Screen name="Details" component={DetailsScreen} />
            </Stack.Navigator>
        </NavigationContainer>
    );
}

export default App;

const styles = StyleSheet.create({
  container: {
    flex: 1,backgroundColor: '#fff',justifyContent: 'center',});

在用expo构建apk并安装到我的android模拟器之后。 仅打开主页,我无法进入详细信息页面

adb shell am start -d exampleapp://details

adb shell am start -d exampleapp://--/details

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)