I'm currently working on setting up a simple linking logic to open an app via an invitation link. The link format would be something like this: [scheme]://auth/[invitaion-code]
To achieve this, I have set up the following linking object to pass to the NavigationContainer
const linking: LinkingOptions<RootStackParamList> = {
prefixes: ['my app scheme'],
config: {
screens: {
Authorizer: {
path: "auth/:code",
},
},
},
};
Additionally, I have defined the following navigation stack:
<NavigationContainer ref={navigationRef} linking={linking}>
<Stack.Navigator
screenOptions={{ headerShown: false }}
initialRouteName={initialRouteName}
>
<Stack.Screen name="Authorizer" component={AuthorizerView} />
</Stack.Navigator>
</NavigationContainer>
Now, my question is how can I access the code
parameter inside my AuthorizerView
Component?
I have attempted the following, but the value always comes out as undefined
const AuthorizerView: React.FC<Props> = ({ navigation }: Props) => {
const {code} = navigation.params;
Here is the log of the navigation object:
{"addListener": [Function addListener], "canGoBack": [Function canGoBack], "dispatch": [Function dispatch], "getId": [Function getId], "getParent": [Function getParent], "getState": [Function anonymous], "goBack": [Function anonymous], "isFocused": [Function isFocused], "navigate": [Function anonymous], "pop": [Function anonymous], "popToTop": [Function anonymous], "push": [Function anonymous], "removeListener": [Function removeListener], "replace": [Function anonymous], "reset": [Function anonymous], "setOptions": [Function setOptions], "setParams": [Function anonymous]}
This issue is similar to this question, but none of the existing answers have proved successful for me, prompting me to ask this question anew.