-
Notifications
You must be signed in to change notification settings - Fork 41
feat: make it easier to navigate to a specific route in navigator #114
Conversation
Codecov Report
@@ Coverage Diff @@
## master #114 +/- ##
==========================================
+ Coverage 93.47% 93.76% +0.28%
==========================================
Files 36 33 -3
Lines 736 722 -14
Branches 189 194 +5
==========================================
- Hits 688 677 -11
+ Misses 40 37 -3
Partials 8 8
Continue to review full report at Codecov.
|
9a0cbd0
to
e8eceb2
Compare
@satya164 I have a root stack navigator with a dev sitemap screen, an auth stack, and tab stack with stacks for each of its screens. These changes fix the problem I was having navigating from a screen inside a stack from my last tab to a screen in the first tab. I can make a However, this only works because the When I make a I can reproduce the behavior using the root sitemap screen. I can navigate to child screens from my root-level sitemap screen to all the screens in my app, but it's only aware of the actual initial routes (rendering back button) of my stacks if I navigate to the tab or root screen within it beforehand. Setting the |
@manticarodrigo it's expected behaviour. if you have never navigated to a screen (the |
We now use the `params` of the route to determine `initialRouteName` and `initialParams` of a navigator. So you can do something like this: ```js navigation.push('Auth', { name: 'Login', params: { token 'xxx' } }) ``` This will navigate to the `Login` screen inside the `Auth` navigator. Closes #90
e8eceb2
to
c383387
Compare
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 API looks awkward for me.
How about
navigation.push('Auth', { screen: { screen: 'Login', params: { token 'xxx' } } })
@satya164 Is there preferred way of "deep linking" to un-initialized routes? In other words, how would I initialize my navigation history without having to navigate to it manually such that I can travel to any screen and retain the |
@manticarodrigo you can use |
@satya164 using So this seems to be a way to "bootstrap" my route structure which then allows me navigate correctly with your new changes, however, it automatically renders the last route in the |
They respect the If you're providing extra routes, the router will try to fix the invalid state and as a result uses the last item in the routes array. You shouldn't provide extra routes in the routes array. They will be automatically created when new screens are pushed. |
@satya164 that makes sense. In the ticket you linked to for 3.11.1, someone suggested a partial fix by doing the following:
Is there an equivalent method in v5? Would this allow me to step into routes and allow them to initialize before the next action? Update: |
@satya164 Any suggestions on how to do deeper navigations into uninstantiated routes? Using |
@manticarodrigo that's what this PR is aiming to solve. also like I mentioned, you can also do |
@satya164 Ok but you previously said that there should not be an awareness of stack structure. This solves the navigation part, but it won't know my initial route unless I navigate to that stack beforehand. Say for example, I have stack that pushes screens one after the next, following a specific order (i.e. registration flow). If I wanted to jump to a specific step, these changes solve that, however, the router has no idea which step of the stack this is, instead it makes that screen the initial route for the stack.
|
@manticarodrigo you are already able to do that with resetRoot({
routes: [
{ name: 'ChannelSettings' },
{ name: 'NotificationSettings', params: { channelId } },
],
}); we'll also make it possible to customize the router in future which will allow you to achieve any behaviour you want. |
@satya164 Ok I was just able to do this now. Thank you! |
Please open a separate bug report with repro code. This is a pull request meant for pull request review. |
We now use the
params
of the route to determineinitialRouteName
andinitialParams
of a navigator.So you can do something like this:
This will navigate to the
Login
screen inside theAuth
navigator.Closes #90