在使用嵌套导航器进行深层链接后,常规导航不起作用

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

我的导航方案是:

const App = () => <AppNavigator />;

const AppNavigator = createSwitchNavigator({
  splash: SplashScreen,
  auth: () => <AuthStack uriPrefix={`${prefix}auth/`} />,
  main: () => <MainDrawer uriPrefix={`${prefix}main/`} />,
});

const AuthStack = createStackNavigator({
  landing: LandingScreen,
  login: {
    screen: LoginScreen,
    path: 'login',
  },
  register: {
    screen: RegisterScreen,
    path: 'signup',
  },
});

const MainDrawer = createDrawerNavigator({
  Home: {
    screen: HomeStack,
    path: 'home',
  },
  Upsell: {
    screen: UpsellScreen,
    path: 'upsell',
  },
});

使用上面的方案,深度链接工作完美,但定期导航,如从loginmain,例如。 this.props.navigation.navigate('main')不工作。

SpashScreen中,有下载的配置数据和授权,如果失败,将阻止用户进入main

我已经确定问题在于SwitchNavigator以及如何在其中定义authmain。将它们改为

auth: AuthStack,
main: MainDrawer,

定期导航工作,但深层链接不工作。

我该如何解决这个问题?

javascript reactjs react-native react-navigation
1个回答
0
投票

你能尝试将uriPrefix移动到将mainauth前缀分隔到路径的根组件吗?

const App = () => <AppNavigator uriPrefix={prefix} />;

const AppNavigator = createSwitchNavigator({
  splash: SplashScreen,
  auth: AuthStack,
  main: MainDrawer,
});

const AuthStack = createStackNavigator({
  landing: LandingScreen,
  login: {
    screen: LoginScreen,
    path: 'auth/login',
  },
  register: {
    screen: RegisterScreen,
    path: 'auth/signup',
  },
});

const MainDrawer = createDrawerNavigator({
  Home: {
    screen: HomeStack,
    path: 'main/home',
  },
  Upsell: {
    screen: UpsellScreen,
    path: 'main/upsell',
  },
});
© www.soinside.com 2019 - 2024. All rights reserved.