nandorojo / expo-next-react-navigation

⛴ Make Next.js and react-navigation play nicely together with an Expo/React Native Web app.
404 stars 32 forks source link

I didn't find any method that could replace reset #92

Closed danielkv closed 2 years ago

danielkv commented 2 years ago

In react-navigation I can "reset" the navigation.

Example:

  1. The user goes from Home to Login page
  2. The user logs in
  3. The navigation is reset and user is sent to Home again
  4. User cannot go back to Login page

I can do this with react-navigation but I didn't figure with expo-next-react-navigation. I know, on web the browser has the history, is completely different. But there is a way to do in mobile and bypass in browser?

nandorojo commented 2 years ago

Could you write what you would code with RN and what you'd expect to happen if this were a feature?

nandorojo commented 2 years ago

Does this not work?

const { replace } = useRouting()
danielkv commented 2 years ago

Does this not work?

const { replace } = useRouting()

I'm actually trying the replace method right now, but the replace method, replaces only the last route right?

This is the exact code I have on my Login page. It runs right after the user Logs in:

import navigation from 'react-navigation/native';

[...]

navigation.reset({
    index: 1,
    routes: [
        { name: 'Home' },
        { name: 'MyAppointments' }
    ]
});
nandorojo commented 2 years ago

Hmm I see. If you were using Next.js, what would you do here, just replace?

nandorojo commented 2 years ago

In my app, when someone signs in, I show them a “welcome” screen with the option to go back.

In my auth screen:

if (user) return <Welcome />

And when they close that, they no longer have a way to get back to that screen.

And then I set the tabs as a function of my state, depending on users who have logged in. I find this to be a better practice, since everything is a function of your state. Could you do that?

danielkv commented 2 years ago

Hmm I see. If you were using Next.js, what would you do here, just replace?

I haven't thought it through kkk. But I think I'd do standard navigation. Probably using replace. I was just wondering if it was possible to reset with this lib. Actually it's not a big deal. I could do as you suggested. it's also good solution!

Thanks again!