Skip to content

Conversation

@danger9224
Copy link
Contributor

I think it'd be nice to expose canGoBack in the Solito useRouter hooks to match React Navigation's capabilities.

  • In React-Navigation, we can just use canGoBack to check if it's possible to navigate back.
  • For web, I used the solution from this StackOverflow answer: https://stackoverflow.com/a/74017719
  • However, with the caveat that the history always seems to start from 2, also in Safari, and also if the link is opened from another webpage (so not only from newtabs)?
    • I think this might need some revision from a more experienced web developer as I'm mostly coming from the mobile stack

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 🙌

@vercel
Copy link

vercel bot commented Jul 30, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
solito-app ❌ Failed (Inspect) Jul 30, 2024 9:42pm
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
solito ⬜️ Ignored (Inspect) Visit Preview Jul 30, 2024 9:42pm

@vercel
Copy link

vercel bot commented Jul 30, 2024

@dnlgrgly is attempting to deploy a commit to the BeatGig Team on Vercel.

A member of the Team first needs to authorize it.

@danger9224 danger9224 changed the title Add canGoBack to routers ↩️❓ Add canGoBack to routers Jul 30, 2024
},
canGoBack: () => {
if (Platform.OS === 'web') {
return window.history?.length && window.history.length > 2
Copy link
Owner

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…

Copy link
Owner

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

Copy link

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();
  }
},

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants