简体   繁体   English

反应原生深层链接不会移动到第二个深层链接

[英]React native deep linking not moving through to 2nd deep link

When using react native deep linking, I am struggling to use a uri with a 2nd path.使用 react native 深度链接时,我正在努力使用带有第二条路径的 uri。 There are examples in the documentation https://reactnavigation.org/docs/4.x/deep-linking文档中有示例https://reactnavigation.org/docs/4.x/deep-linking

The issue I am having is blahh://account --android will link to the correct screen however, blahh://account/keys --android will not.我遇到的问题是 blahh://account --android 将链接到正确的屏幕,但是 blahh://account/keys --android 不会。 This is the same if I add any path to the screens in the AccountStack如果我向 AccountStack 中的屏幕添加任何路径,这也是一样的

I am using react navigation version 4.我正在使用反应导航版本 4。

const AccountStack = createStackNavigator(
    {
        Account: {
            screen: Account,
            path: '',
            navigationOptions: {
                ...accountNavigationOptions,
                ...Account.navigationOptions,
            },
        },
        AccountLoginAndSecurity: {
            screen: AccountLoginAndSecurity,
            path: '',
            navigationOptions: () => ({
                ...defaultNavigationOptions,
                headerTransitionPreset: 'uikit',
            }),
        },
        CreateAccount: {
            screen: CreateAccount,
            path: '',
            navigationOptions: () => ({
                ...defaultNavigationOptions,
                headerTransitionPreset: 'uikit',
            }),
        },
        KeysList: {
            screen: KeysList,
            path: 'keys',
            navigationOptions: () => ({
                ...defaultNavigationOptions,
                headerTransitionPreset: 'uikit',
            }),
        },
        AccountSwitch: createAnimatedSwitchNavigator(
            {
                AccountLoading: {
                    screen: AccountLoading,
                    path: '',
                    params: {
                        theme: 'orange',
                        navigateScreen: 'CreateAccountOrLogin',
                    },
                },
                CreateAccountOrLogin: CreateAccountOrLogin,
                Continue: AccountMenu,
            },
            {
                initialRouteName: 'AccountLoading',
                transition: createSwitchTransition(),
            }
        ),
    },
    {
        defaultNavigationOptions: accountNavigationOptions,
    }
);

export const TabNavigator = createBottomTabNavigator(
    {
        Explore: {
            screen: ExploreStack,
            path: '',
        },
        Bookings: {
            screen: YourBookingsStack,
            path: '',
        },
        Account: {
            screen: AccountStack,
            path: 'account',
        },
    },
    {
        defaultNavigationOptions: ({ navigation }) => ({
            // eslint-disable-next-line react/display-name
            tabBarIcon: ({ focused }): React.ReactNode => {
                const { routeName } = navigation.state;
                let iconName;
                if (routeName === 'Explore') {
                    focused
                        ? (iconName = require('assets/icons/bottom_tab_icons/explore_tab_icon.png'))
                        : (iconName = require('assets/icons/bottom_tab_icons/explore_tab_icon_unselected.png'));
                } else if (routeName === 'Bookings') {
                    focused
                        ? (iconName = require('assets/icons/bottom_tab_icons/bookings_tab_icon.png'))
                        : (iconName = require('assets/icons/bottom_tab_icons/bookings_tab_icon_unselected.png'));
                } else if (routeName === 'Account') {
                    focused
                        ? (iconName = require('assets/icons/bottom_tab_icons/account_tab_icon.png'))
                        : (iconName = require('assets/icons/bottom_tab_icons/account_tab_icon_unselected.png'));
                }
                return <Image source={iconName} />;
            },

            tabBarOptions: {
                showLabel: false,
                style: {
                    elevation: 3,
                    borderTopColor: 'transparent',
                    backgroundColor: '#fff',
                    height: 50,
                },
            },
        }),

        navigationOptions: () => ({
            headerBackTitle: null,
            headerTitleStyle: { color: 'orange' },
        }),
    }
);

According to the documentation :根据文档

If we have nested navigators, we need to provide each parent screen with a path.如果我们有嵌套的导航器,我们需要为每个父屏幕提供一个路径。 All the paths will be concatenated and can also be an empty string.所有路径都将连接起来,也可以是空字符串。 This path spec would be friends/chat/:user.此路径规范将是friends/chat/:user。

So, if you want to pass a query parameter with your URL, you need to pass it with path props like this:所以,如果你想用你的 URL 传递一个查询参数,你需要像这样传递path道具:

Account: {
  screen: AccountStack,
  path: 'account/:key'
}

I just looked at the codebase and Account links through to the account screen before going to the keys screen.在转到密钥屏幕之前,我只是查看了代码库和帐户链接到帐户屏幕。

Account: {
        screen: Account,
        path: '',
        navigationOptions: {
            ...accountNavigationOptions,
            ...Account.navigationOptions,
        },
    },

so the fix was to add an empty path to this in the accountstack then it worked fine when going to npx uri-scheme open blahh://account/keys --android所以修复是在 accountstack 中添加一个空路径然后它在去 npx uri-scheme open blahh://account/keys --android 时工作正常

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM