Closed IlyasNN closed 1 year ago
This is actually very easy 🙂 All you need to do is put the entire tabView into another route.
E.g. if we have the ContentView
:
struct ContentView: View {
var body: some View {
SwitchRoutes {
Route("/settings/*", content: SettingsView())
Route {
ViewWithTabs() // <--- the 'tab view'
}
}
}
}
We have a route that renders SettingsView
for the path "/settings/*"
. For any other path the ViewWithTabs
(in this case the so-called tabView) will be rendered.
Then, somewhere in ViewWithTabs
(maybe as a tab itself) you need a NavLink
that redirects to an absolute path (in this case "/settings"
):
NavLink(to: "/settings") {
VStack {
Image(systemName: "gears")
Text("Settings")
}
}
In this case the entire ViewWithTabs
will be replaced with the SettingsView
, and thus allowing an entirely different flow of routing.
Is there a way how I can save state of tabTab views with it's tabs' contents?
Sadly not automatically, no. You will need to come up with your own solution. (Maybe an environment object) This is a challenge you will face very often in SwiftUI 🙂
It's very sad( Anyway, thank you for fast answer. I suppose this issue can be closed
How can I Create one more navigation stack above tabView?
So I need to present a few different flows under each of tab. But I can't fine approach to do that. I had a look in examples and there is no scenario I need.
I'll explain using one of examples: From one of the tabs I what to navigate further:
How can I push View above tabView, not inside?
Please help)