JamesSedlacek / Routing

SwiftUI library for abstracting navigation logic from views

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Do nested routers work?

metasidd opened this issue · comments

Do nested routers work? Currently I have an app that needs a multiple router setup - a global router(managing login states) and a local router(managing tab specific routing). The global router on its own works perfectly, but the moment I introduce multiple routers within a tab view, even the global router stops working.

This is roughly the structure I have:

enum GlobalRouter: Router {
   case loading // this is the default state on app open
   case loggedIn
   case loggedOut
}

enum Tab1Router: Router {
   case main
   case detailView
}

enum Tab2Router: Router {
   case main
   case detailView
}

// The view hierarchy
RoutingView(GlobalRouter) {
   RoutingView(Tab1Router)
   RoutingView(Tab2Router)
}

Curious if you have thoughts around this topic, or if there's other approaches I should be taking here.

Each tab should have its own RoutingView and router.
I wouldn't suggest having a global router.
You can't (or shouldn't) wrap a TabView with a NavigationStack.