t4t5 / react-native-router

Awesome navigation for your React Native app.
MIT License
1.17k stars 155 forks source link

Reset route stack #30

Closed AdamBrodzinski closed 9 years ago

AdamBrodzinski commented 9 years ago

Is there any way to reset the route stack back to 0? My use case is that I need to go through a login process and I don't want users to be able to swipe back to the login after they've logged in.

Changing the button somewhat works but you can still swipe back.

Thanks!

dimoreira commented 9 years ago

@AdamBrodzinski Did you found a solution for this? I'm running through the same problem.

AdamBrodzinski commented 9 years ago

@dimoreira I ended up rolling my own using Navigator. I copied some of the CSS from here to get a basic layout. You also might be able to expose the navigator object, if you can it's not documented.

This is a good reply on SO on how to get Navigator working in a minimal fashion.

http://stackoverflow.com/questions/30513523/how-can-i-remove-the-previous-route-from-router

If you do go this route I would recommend passing in the view instead of using a switch statement as it can egt a bit messy.

NavigatorIOS might be fixed now but it had a bug with the title not resetting when you reset the route stack.

dimoreira commented 9 years ago

@AdamBrodzinski I was hooked to this implementation more because the custom title components than the routing methods itself. Did you use some kind of custom title component too in your implementation?

dimoreira commented 9 years ago

@t4t5 There is some way to reset the route stack to index but changing the component? Like in an Login flow.

Use Case An user opens the app in LoginView and after login I want to reset route stack to be the ProjectListView, to prevent the user to slide back to the LoginView.

t4t5 commented 9 years ago

@dimoreira The current solution this.props.reset() takes the user all the way back to the route with index 0. So if that's where you ProjectListView is I guess it should work?

dimoreira commented 9 years ago

@t4t5 If I completed my login flow on LoginView and called this.props.toRoute on the end of the authentication process to go to my ProjectListView, then my index is 1 on this page. Not 0.

If I call the this.props.reset() after this, the flow will be redirect to LoginView again.

t4t5 commented 9 years ago

@dimoreira Ah I see. So you basically want to be able to jump back to a specific route from the stack of visited routes? Unfortunately that's not what this action does. It should be simple to implement though as an abstraction of the existing popToRoute(route) in React Native's Navigator object.

Feel free to try to implement it. It should be very similar to the reset()-action. Otherwise you could create a new issue and I'll look into it soonish. :)

thecodecafe commented 6 years ago

@t4t5 Anything on this yet? Really need it right now.

dimoreira commented 6 years ago

@thecodecafe There are now other native solutions to the ReactNative core. I suggest the following reading: https://facebook.github.io/react-native/docs/navigation.html

thecodecafe commented 6 years ago

@dimoreira Yeah, I've been using react-navigation for some time now, have no problems with it so far.