router
router copied to clipboard
add easier system for popping multiple screens in a stack
Summary
Given this navigation, I want the links to act like bottom tabs.
- If you are drilled down into "Buy" nav and click "Buy", the app replaces the nav stack with the '/buy' route which is the initial screen for that tab
- If you are drilled down into the "Sell" nav and click "Buy", the app jumpsTo the Buy tab. If you click back to "Sell" the app takes you to the last screen you were on
However, if I'm drilled down into "Buy" and click "Buy" (which calls replace('/buy')
, nothing happens
Minimal reproducible example
const segments = useSegments();
const currentSegment = segments.slice(-1)[0];
const isInPath = segments.includes(segment);
const isCurrent = currentSegment === segment;
const router = useRouter();
const handlePress = useCallback(
() =>
isCurrent
? null
: isInPath
? router.replace(`/${segment}`)
: navigator.jumpTo(segment),
[isCurrent, isInPath, router, segment, navigator]
);