Fix TabsRoute behaviour
See original GitHub issueTabsRoute should implement two behaviours:
- it should save the state for each child route and restore it when switching tabs
- it should reset a child’s state if that child is being navigated to twice
Given the following route config:
<Router>
<TabsRoute path="/" ...>
<StackRoute path="/foo" ...>
<Route path="a" ... />
<Route path="b" ... />
</StackRoute>
<Route path="/bar" .../>
</TabsRoute>
</Router>
Visiting routes should lead to the following results respectively:
- /foo --> show /foo
- /foo/a --> show /foo/a
- /foo/b --> show /foo/b
- /bar --> show /bar
- /foo --> show /foo/b (a tab route saves and restores its children’s state)
- /foo --> should reset stack of the child stack route and show /foo
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Infinite routes behavior · Issue #281 - GitHub
Hi, I'm working on a Planning component, on a feature that allows sliding between days. I think this component can achieve this behaviour....
Read more >URL not changing consistently in React router - Stack Overflow
The behavior I get is odd. Sometimes the URL changes as I switch between tabs. It works great. Then sometimes the URL doesn't...
Read more >Strange router behaviour [Ionic 6 Vue]
Hello. I am experiencing some weird behavior when trying to create a route with an optional parameter. Here is the router code:
Read more >Router tutorial: tour of heroes - Angular
Behind this behavior is the router's canDeactivate guard. ... how to create multiple routing modules and import those routing modules in the correct...
Read more >Navs - Bootstrap
JavaScript behavior. Use the tab JavaScript plugin—include it individually or through the compiled bootstrap.js file—to extend our navigational tabs and pills ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@jonathanewerner @joonhocho That is supported. Previously, there was a bug in NavigationExperimental that dropped component state when swtiching tabs. But that’s now fixed, and
<Route>
and its siblings should now retain component state on all navigation state updates. This includes<ScrollView>
state e.g. scroll position, animation state.UINavigationContoller extends UIViewController and uses the good old lifecycles inherited from it. It does retain all
UIViewController
instances that are then pushed to it. Very similar to how we do it. Both<TabsRoute>
and<StackRoute>
retain references to your previously focused views. Here’s how they would look when you inspect the view hierarchy.<StackRoute>
with 3 active viewsHere a
<Pop>
would drop the focused view revealing the previous view in the stack with a transition animation. The views in a stack are never unmounted during a transition so you keep your component state. Transition animations can also be customized usingtransitionRegistry
.<TabsRoute>
with 3 active viewsBy default, transition animations are turned off for
<TabsRoute>
mirroring native behavior. But there’s nothing preventing you from making them animate when switching tabs. Aviato example does this for its inner “swticher” tabs.<TabsRoute>
is also smart enough to lazily render its tabs. So when your app launches, you will have only one of the tabs (focused view) rendered, but once you tap other tabs, all are retained until you kill the app.Are you perhaps running into a bug we can try to reproduce and fix?
🍺
Thanks @jmurzy for such detailed answer. I once noticed that tabs on react native apps did not retain previous view states, but did not know that it was fixed. It’s pretty cool to know how they can lazily render other tabs.