microsoft / react-native-windows

A framework for building native Windows apps with React.
https://microsoft.github.io/react-native-windows/
Other
16.33k stars 1.14k forks source link

Deep linking doesn't work if the app isn't running #6996

Open qmatteoq opened 3 years ago

qmatteoq commented 3 years ago

Environment

Run the following in your terminal and copy the results here.

  1. npx react-native --version:

4.13.1

  1. npx react-native info:
System:
    OS: Windows 10 10.0.19042
    CPU: (8) x64 Intel(R) Core(TM) i7-1065G7 CPU @ 1.30GHz
    Memory: 1.98 GB / 15.60 GB
  Binaries:
    Node: 12.9.1 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.5 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 6.10.2 - C:\Program Files\nodejs\npm.CMD
    Watchman: Not Found
  SDKs:
    Android SDK: Not Found
    Windows SDK:
      AllowDevelopmentWithoutDevLicense: Enabled
      AllowAllTrustedApps: Enabled
      Versions: 10.0.14393.0, 10.0.15063.0, 10.0.17763.0, 10.0.18362.0, 10.0.19041.0
  IDEs:
    Android Studio: Not Found
    Visual Studio: 16.8.30907.101 (Visual Studio Enterprise 2019), 16.9.30914.41 (Visual Studio Enterprise 2019)
  Languages:
    Java: Not Found
    Python: Not Found
  npmPackages:
    @react-native-community/cli: Not Found
    react: 16.13.1 => 16.13.1
    react-native: 0.63.2 => 0.63.2
    react-native-windows: ^0.63.0-0 => 0.63.18
  npmGlobalPackages:
    *react-native*: Not Found

Steps To Reproduce

  1. Open the manifest of the application and, in the Declaration tab, register a protocol (for example, foo:)
  2. In the React Native code, reference the Linking module, then add a button which invokes the following function:

    const getLinkUrl = async() => {
    const url = await Linking.getInitialURL();
    console.log(url);
    }
  3. Close the application
  4. Press Win-R and invoke the application using the protocol you have registered (for example, by typing foo:/details?id=1)

Expected Results

The application starts and, when I press the button, the Linking.getInitialURL() function returns the URL used to invoke the app. Instead, I always get null. The problem happens only if the app isn't running. If it's already running, the app is brought to foreground and the code works.

Snack, code example, screenshot, or link to a repository:

The official sample app in the React Native for Windows repo implements this scenario.

asklar commented 3 years ago

We should look at deep-linking all up in terms of activations that aren't just the vanilla "launch" scenario, and what logic to handle these we should have in ReactApplication and what we allow community modules to do.

qmatteoq commented 3 years ago

Scenario highlighted in issue #4396 is very interesting to me as well. One of the challenges that prevented me to leverage the App Service approach in a mixed UWP - Win32 scenario is that, currently, I don't have a way to pass an argument from the OnBackgroundActivated() event (the reference to the App Service connection) to the native module that needs to communicate with this connection.

stmoy commented 3 years ago

@vmoroz has started taking a look, assigning to him. Please feel free to unassign if appropriate.

chrisglein commented 3 years ago

@vmoroz There was a comment made back in February that there was something in-flight for this. Still true? Or should we open this up for someone else?

Victor0814gui commented 1 year ago

Is this still being reviewed?

Victor0814gui commented 1 year ago

Linkgin in fact does not work if the application is not open, but through navigation it is possible to capture the parameters

https://github.com/microsoft/react-native-windows/assets/92493696/06dc1e18-c146-4b70-a7d5-822f9d1b9259