Skip to content

Commit

Permalink
feat: modify result state of global navigator
Browse files Browse the repository at this point in the history
  • Loading branch information
timepresent95 committed Oct 10, 2024
1 parent 3d03287 commit 181e7df
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/utils/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import { type RouteName } from '@/constants';
export const navigationRef =
createNavigationContainerRef<Record<RouteName, undefined>>();

export function navigate(name: RouteName) {
if (
navigationRef.isReady() ||
!navigationRef.getState().routeNames.some(v => v === name)
) {
return false;
export function navigate(routeName: RouteName) {
if (!navigationRef.isReady()) {
throw new Error('Can not find connected navigation container.');
}

navigationRef.navigate(name);
return true;
const { routes } = navigationRef.getState();
if (routes.find(route => route.name === routeName)) {
throw new Error('Tried to navigate to an unavailable route.');
}

navigationRef.navigate(routeName);
}

0 comments on commit 181e7df

Please sign in to comment.