We're trying to add deep-linking to our Expo react native app using Expo Linking that opens a specific path within the app using something like this:
myapp://home/items/order-details
. However, when trying to use that deeplink url we are only taken to the home screen.
But, when we use this url: myapp://profile
, it does indeed open the profile screen instead of the home screen. It seems to be working for top-level routes but not the nested ones. Is there a way to get the deeplink url to go directly to the order-details screen using our navigation?
Our App.js looks like this:
import {createRootNavigator} from './router';
const RootNav = createRootNavigator();
const prefix = Expo.Linking.makeUrl('/');
export default class App extends React.Component {
render() {
return (
<Root>
<RootNav uriPrefix={prefix}/>
</Root>
)
}
This is our router.js
export const MenuNav = createStackNavigator ({
Menu: {screen: Menu, path: 'menu'},
OrderDetails: {screen: OrderDetails, path: 'order-details'}
}
);
export const UserCreate = createStackNavigator ({
Profile: {screen: Profile}
});
export const Tabs = createBottomTabNavigator({
'Home': {
screen: Home,
path: 'home-tab'
},
'Items': {
screen: MenuNav,
path: 'items'
}
},
{tabBarComponent: (props) => {
return (
<TabBar
{...props}
/>
);
},
tabBarPosition: 'bottom',
},
);
export const createRootNavigator = () => {
return createDrawerNavigator ({
Home: {
screen: Tabs,
path: 'home'
},
Profiles: {
screen: UserCreate,
path: 'profile'
},
});
Because the navigators are so nested, instead of adding the uriPrefix
in the RootNav
on the App.js, try adding it to the tabBarComponent. So, in your router.js you should add the uriPrefix = {prefix}
to TabBar. Also, since order-details
is nested within another stack, it might be necessary to add another stack just for the OrderDetails
screen since it is already its own screen.
router.js should look like this:
const prefix = Expo.Linking.makeUrl('/');
export const MenuNav = createStackNavigator ({
Menu: {screen: Menu, path: 'menu'},
OrderDetails: {screen: OrderDetails, path: 'order-details'}
}
);
export const UserCreate = createStackNavigator ({
Profile: {screen: Profile}
});
export const Tabs = createBottomTabNavigator({
'Home': {
screen: Home,
path: 'home-tab'
},
'Items': {
screen: MenuNav,
path: 'items'
}
},
{tabBarComponent: (props) => {
return (
<TabBar
{...props}
uriPrefix={prefix}
/>
);
},
tabBarPosition: 'bottom',
},
);
export const createRootNavigator = () => {
return createDrawerNavigator ({
Home: {
screen: Tabs,
path: 'home'
},
Profiles: {
screen: UserCreate,
path: 'profile'
},
OrderDetails: {
screen: OrderDetails,
path: 'history/order/:orderId'
}
});