-
-
Notifications
You must be signed in to change notification settings - Fork 188
↩️❓ Add canGoBack
to routers
#481
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Skipped Deployment
|
@dnlgrgly is attempting to deploy a commit to the BeatGig Team on Vercel. A member of the Team first needs to authorize it. |
@@ -140,6 +140,13 @@ export function useRouter() { | |||
navigation?.goBack() | |||
} | |||
}, | |||
canGoBack: () => { | |||
if (Platform.OS === 'web') { | |||
return window.history?.length && window.history.length > 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should return a Boolean, right? It also isn’t SSR safe…
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we need to use useSyncExternalStore for web
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello, I hope you're doing well. I wanted to share my thoughts on this feature. I'm not quite sure how to contribute directly, so I thought I'd leave my suggestion here.
I believe this feature would be great! However, I don’t think we necessarily need to use useSyncExternalStore. A simple check on the browser’s history might be sufficient.
canGoBack: () => {
if (typeof window !== 'undefined' && Platform.OS === 'web') {
return window.history?.length > 1;
} else {
return navigation?.canGoBack();
}
},
I think it'd be nice to expose canGoBack in the Solito useRouter hooks to match React Navigation's capabilities.
canGoBack
to check if it's possible to navigate back.I've tested it locally and it seems to work fine both on web and native. This is my first contribution so all feedback is much appreciated 🙌