重置用户密码时,我对另一个第三方服务也有同样的问题。我仍然没有找到解决方案,但我注意到 react-navigation 不会将 url 片段“#”视为特殊字符。相反,它会尝试将初始 url 与配置对象中配置的路径进行比较。
例如,如果您将屏幕的路径配置为“/loginredirect#id_token=sometoken”而不是配置对象中的“/loginredirect”,您的应用程序将在正确的屏幕上打开。
const config = {
screens: {
Auth: {
screens: {
Login: 'loginredirect#id_token=sometoken',
},
},
},
};
问题是 id_token 是不可预测的,因此不可能硬编码这个值。
我尝试在链接对象中使用订阅参数,但它仅在应用程序已经打开时才有效:
const linking: LinkingOptions<RootStackParamList> = {
prefixes,
config,
subscribe(listener) {
const onReceiveURL = ({ url }: { url: string }) => listener(url);
// Listen to incoming links from deep linking
const subscription = Linking.addEventListener('url', onReceiveURL);
// Get the inital URL
// Call the listener to let React Navigation handle the formatted URL
Linking.getInitialURL().then((value) => {
if (value != null) {
if (value.includes('#')) {
const newUrl = value.substring(0, value.indexOf('#'));
listener(newUrl);
}
}
});
// Clean up the event listeners
return () => subscription.remove();
},
};
我仍在寻找处理此案的正确方法...