Intercept a DeepLink with navigation component

1.9k views Asked by At

I am using Navigation Component in my app, and I'm using it to handle my deep links. It's working great, but as it stands, it really only works as intended if my user is logged in. That's because I have the deep link declared in a module that assumes the user is authenticated. Authentication is done in another module.

Here is a rough diagram of my navigation graph for my single Activity app.

NavHostFragment (app module, MyActivity)
|
|--- MyLoginFragment (login module, login_navigation.xml)
|         |
|         `---...
|
|--- MyHomeFragment (home module, home_navigation.xml)
|         |
|         `--- MyFinalFragment (my-app://deep-link/uri)
.

I have a deep link set up in home_navigation.xml inside the HomeFragment <fragment> element.

I need to intercept this deep link, possibly in the Activity, and route them back to the login module when the user is not logged in.

Is there a Navigation Component idiom for this? Or am I forced to check the Intent data in onCreate of the MyHomeFragment/MyActivity and manually navigate?

0

There are 0 answers