frzi / swiftui-router

Path-based routing in SwiftUI
MIT License
919 stars 44 forks source link

Router for tabview switch #7

Closed ghost closed 4 years ago

ghost commented 4 years ago

How to switch to a different tab view.

From Route, i can get expected tab via parameters.tab, however, how can i hand over this value to @State $selection?

@State private var selection = 0
Route(path: "tabView/:tab") { info in
                    self.myTabView(activeTab: info.parameters.tab ?? "")
                }

TabView(selection: $selection) {
...
}
frzi commented 4 years ago

Unfortunately I don't think there's a way to use SwiftUI-Router for views like TabView en NavigationView. These all rely on a binding (like @State), whereas SwiftUI-Router doesn't.

If there's a way to make the two work I'd gladly hear it! But at this point, I think your best option is to make a custom TabView. Sorry. 😞

ghost commented 4 years ago

Thank you