-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
048ffff
commit 40dabf4
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// | ||
// Router.swift | ||
// StudyFora | ||
// | ||
// Created by Carissa Farry Hilmi Az Zahra on 26/12/23. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct Routes: View { | ||
let route: Router.Destination | ||
|
||
var body: some View { | ||
switch route { | ||
case .register: | ||
RegisterView() | ||
case .profile: | ||
ProfileView() | ||
} | ||
} | ||
} | ||
|
||
final class Router: ObservableObject { | ||
|
||
public enum Destination: Codable, Hashable { | ||
case register | ||
case profile | ||
} | ||
|
||
@Published var navPath = NavigationPath() | ||
|
||
func navigate(to destination: Destination) { | ||
navPath.append(destination) | ||
} | ||
|
||
func navigateBack() { | ||
navPath.removeLast() | ||
} | ||
|
||
func navigateToRoot() { | ||
navPath.removeLast(navPath.count) | ||
} | ||
} |