expo / router

[ARCHIVE]: Expo Router has moved to expo/expo -- The File-based router for universal React Native apps
https://docs.expo.dev/routing/introduction/
1.36k stars 113 forks source link

Remove navigation context requirement for `canGoBack()` #839

Closed blainekasten closed 1 year ago

blainekasten commented 1 year ago

Motivation

Our application runs a lot of async logic on app start before rendering the routing tree. During this time we had a utility function to wrap the router.back API in which we did the following:

const useNavigation = () => {
  const router = useRouter();

  return {
    navigate: router.push,
    back: router.canGoBack() ? router.back : () => router.push('/')
  };
}

Unexpectedly, the function call to canGoBack() was throwing an assertion about trying to navigate without the navigation context.

Execution

I changed the code via the github UI with zero testing or validation. 🙃

Test Plan

Please advise how I can best support and test this