首页 > 解决方案 > 为什么当应用程序关闭时,react-navigation 不能从深层链接打开正确的 url?

问题描述

我有一个深度链接配置设置,可以在设备上单击 URL 时打开特定页面。当应用程序在后台打开时,这工作正常,但如果应用程序关闭,它只会打开应用程序而不导航。

这是我的链接配置:

const linking = {
    prefixes: ["appname://"],
    config: deepLinkRouting,
    getStateFromPath(path:string, options:any) {
        //build custom params
    },
    async getInitialURL() {
        // Check if app was opened from a deep link
        const url = await Linking.getInitialURL();
        if (url != null) {
            return url;
        }
    },
    subscribe(listener) {
        const onReceiveURL = ({ url }) => listener(url);
        Linking.addEventListener('url', onReceiveURL);

        return () => {
            // Clean up the event listener
            Linking.removeEventListener('url', onReceiveURL);
        };
    },
}

这个链接对象是作为道具提供给我的<NavigationContainer/>

我正在使用npx uri-scheme open命令在模拟器上对此进行测试。我注意到当您关闭应用程序并重新打开它时,应用程序会重新构建,所以我想知道这是否会使测试无效。任何帮助表示赞赏!

标签: iosreact-nativereact-navigationdeep-linking

解决方案


推荐阅读