-
Notifications
You must be signed in to change notification settings - Fork 24.3k
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
React Native this.props.navigator.push can't push a component twice for Navigator #3076
Comments
closing this issue since Facebook does not maintain NavigatorIOS |
reopening this issue since I am having the same problem with |
@kevinzzz007 Not sure wether this is an issue with the I wonder If you replace |
@hedgerwang so it works if I push a component that hasn't been pushed before, but if I push something already on the stack then it gives me this error
|
@hedgerwang using a dummy component does work. To be more specific, I have a file called DriverCreateAccount.js, and have a view in it. I already pushed this onto the navigator, then when I try to do it again, and when I try to print out the route.component, it gives me
so there is some issue with importing the .js file twice? Because importing it once works perfectly fine... |
I think this is my issue: |
Coping the answer from the above Stackoverflow question: Approach 1: Lazy Loading Alpha and Beta don't need each other until the user navigates from one scene to the next. For the app to reach this state, Alpha must have defined its exports (that is, module.exports = Alpha must have run for your app to have rendered an Alpha component). So, when the user is navigating to the scene displaying Beta, it is safe for Beta to require Alpha and therefore it is safe to require Beta at this point in time. // Alpha.js
}); Approach 2: Single Module Another solution is to put Alpha and Beta in the same JS file to remove a cycle between modules. You would then export both components from the new mega-module. // AlphaBeta.js // index.js |
Is there a best practice for this at Facebook? @hedgerwang |
Pretty sure lazy loading is the best solution (I worked on JS modules and that specific implementation of require.js). |
We don't do lazy-loading at Fb yet, but it would do the trick. The way we currently do this is to have a big mapping from routes to components that gets used in |
@ide thanks! I will probs use that for now then @ericvicenti I see, could you share some examples on how to do this? Thank you so much! |
Here is a highly simplified example of the approach we take:
|
@ericvicenti thank you so much! |
Just to clarify for future reference, this code worked for me:
I used this as a reference: |
I am getting similar error on the simulator: I have the following code structure: What I am trying to get a navbar for Android myself. |
@isikfsc I am on iOS so not sure how helpful this is, but you have |
+1, this solution rocks. Thanks @ericvicenti and @kevinzzz007 |
When I use a function like this:
, if I have already pushed the DriverCreateAccount component in a previous .js file, then it seems I can't use the push again, does it mean I have to use pop to get back to where I want to go? I can't push the same component twice to the stack?
The text was updated successfully, but these errors were encountered: