ant*_*ñoz 7 deep-linking typescript react-native react-navigation
我正在尝试在带有反应导航的反应本机项目中使用深层链接,但我在两个平台(ios 和 android)中都遇到了一些奇怪的场景。
我的代码导航容器
const linking = {
prefixes: ['https://latineo.com', 'latineo://'],
config: {
Home: {
path: 'homestack',
initialRouteName: 'Explore',
screens: {
Explore: 'explore',
Posts: 'posts',
Favorites: 'favorites',
Settings: 'settings',
},
},
ExploreOptions: {
path: 'explorestack',
initialRouteName: 'Restaurants',
screens: {
Restaurants: 'rts',
ShowRestaurants: 'restaurants',
ShowRestaurant: 'restaurant/:id',
},
}
},
};
<NavigationContainer
theme={navigatorTheme}
ref={(nav: any) => {
navigator = nav;
NavigationService.setNavigator(navigator);
}}
linking={linking}
fallback={<LoadingIndicator
size='giant'
></LoadingIndicator>}
onStateChange={(nav) => {
console.log("AppNavigator -> nav", nav)
}}
>
{isAuth && <HomeNavigator />}
{!isAuth && didTryAutoLogin && didOnboard && didPermission && <AuthNavigator />}
{!isAuth && didTryAutoLogin && !didOnboard && <OnboardScreen />}
{!isAuth && didTryAutoLogin && didOnboard && !didPermission && <LocationPermissionScreen />}
{!isAuth && !didTryAutoLogin && <IsAuthScreen />}
</NavigationContainer>
Run Code Online (Sandbox Code Playgroud)
主页导航
const Stack = createStackNavigator<HomeParamList>();
export const HomeNavigator = (): React.ReactElement => {
return (
<Stack.Navigator
initialRouteName={'Home'}
headerMode='none'
>
<Stack.Screen name='Home' component={HomeTabsNavigator} />
<Stack.Screen name='ExploreOptions' component={LayoutsNavigator} />
<Stack.Screen name='CreateOptions' component={PostNavigator} />
<Stack.Screen name='FavoritesOptions' component={FavoritesNavigator} />
<Stack.Screen name='SettingsOptions' component={SettingsNavigator} />
</Stack.Navigator>
);
};
export const HomeTabsNavigator = (): React.ReactElement => {
return (
<BottomTab.Navigator
screenOptions={TabBarVisibleOnRootScreenOptions}
initialRouteName={'Explore'}
tabBar={props => <HomeBottom {...props} />}>
<BottomTab.Screen name='Explore' component={LayoutsScreen} />
<BottomTab.Screen name='Post' component={PostsScreen} />
<BottomTab.Screen name='Favorites' component={LayoutsScreen} />
<BottomTab.Screen name='Settings' component={SettingsContainer} />
</BottomTab.Navigator>
);
};
Run Code Online (Sandbox Code Playgroud)
场景一
当我尝试使用 xcrun simctl openurl 启动 latineo://homestack/explore 或 latineo://homestack/settings、explorestack/restaurant/:id 等(后台应用程序)时,它工作正常,但是当应用程序关闭(被杀死)时它总是打开 homestack/explore。
场景 2 当我尝试使用 explorestack/restaurant/:id 时,它可以工作,但是当我按下一个按钮 navigation.back() 时,它返回到一个空白屏幕(如果我使用这个白屏上的手势,我可以返回到我的主屏幕)。 
当我使用后退按钮尝试使用 explorestack/restaurants 时,会发生类似的事情,它导航到同一屏幕但没有标题。
| 归档时间: |
|
| 查看次数: |
1326 次 |
| 最近记录: |