Skip to content

Instantly share code, notes, and snippets.

@emeraldsanto
Last active September 4, 2021 03:44
Show Gist options
  • Select an option

  • Save emeraldsanto/47acb7e2872c703e91d63bced0fa914f to your computer and use it in GitHub Desktop.

Select an option

Save emeraldsanto/47acb7e2872c703e91d63bced0fa914f to your computer and use it in GitHub Desktop.
Achieving type safe deep linking in React Native with react-navigation #3
import { createStackNavigator } from '@react-navigation/stack';
import { Screen } from 'some-path/Screen';
import { ScreenOne } from 'some-path/ScreenOne';
import { ScreenTwo } from 'some-path/ScreenTwo';
import { ScreenThree } from 'some-path/ScreenThree';
const routeConfigMap = {
[Screen.One]: { screen: ScreenOne },
[Screen.Two]: { screen: ScreenTwo },
[Screen.Three]: { screen: ScreenThree, options: { /* ... */ } },
// ...
};
const Stack = createStackNavigator();
export const SomeStack = () => {
return (
<Stack.Navigator screenOptions={{ /* ... */ }}>
{Object.keys(routeConfigMap).map((key) => (
<Stack.Screen
key={key}
name={key}
options={routeConfigMap[key as keyof typeof routeConfigMap].options}
component={routeConfigMap[key as keyof typeof routeConfigMap].screen}
/>
))}
</Stack.Navigator>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment