我的导航方案是:
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',
},
});
使用上面的方案,深度链接工作完美,但定期导航,如从login
到main
,例如。 this.props.navigation.navigate('main')
不工作。
在SpashScreen
中,有下载的配置数据和授权,如果失败,将阻止用户进入main
。
我已经确定问题在于SwitchNavigator
以及如何在其中定义auth
和main
。将它们改为
auth: AuthStack,
main: MainDrawer,
定期导航工作,但深层链接不工作。
我该如何解决这个问题?
你能尝试将uriPrefix
移动到将main
和auth
前缀分隔到路径的根组件吗?
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',
},
});