At last, I have achieved a version of the Router pattern that I am happy with and addresses the problems I intended to solve when I started.
Remove navigation specific APIs from SwiftUI views.
Prevent views from knowing about other views and how to build them.
Shield views from knowing how other views are navigated to.
It is the result of all the exploratory work and iterations I made in previous posts:
Table of Contents
Removing Navigation APIs from SwiftUI Views
Introducing the RoutingView as a wrapper.
Decoupling views from SwiftUI navigation APIs.
Injecting a Router instance into the view hierarchy.
Moving Navigation Logic to the Router
How the Router manages navigation.
Simplifying view navigation with routeTo(_).
Programmatically manipulating the navigation stack.
Achieving Modularity with the Routable Protocol
Defining navigation for modularized codebases.
Eliminating circular dependencies in the library.
Example implementation of the Routable protocol.
Next Steps and Community Contributions
Future plans for the library.
How to contribute or provide feedback.
You can download the entire code for this library below: