Junior — Middle
Who is the Router role intended for in the MVVM architecture?
sobes.tech AI
Answer from AI
In MVVM architecture, the role of the Router is usually not directly related to the Model, View, or ViewModel. The Router is responsible for navigation between screens of the application, that is, for transitions and routing. In iOS applications, the Router is often implemented as a separate component that manages transitions between ViewControllers, is called from the ViewModel or Coordinator, and helps separate navigation logic from business logic and presentation.
Example: The ViewModel informs the Router that it needs to navigate to the next screen, and the Router performs the transition.
protocol Router {
func navigateToDetail()
}
class AppRouter: Router {
weak var navigationController: UINavigationController?
func navigateToDetail() {
let detailVC = DetailViewController()
navigationController?.pushViewController(detailVC, animated: true)
}
}