Skip to content

Commit

Permalink
feat: add router
Browse files Browse the repository at this point in the history
  • Loading branch information
carissafarry committed Dec 27, 2023
1 parent 048ffff commit 40dabf4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions StudyFora.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
0517F1FE2AE75DF700FD855A /* FirebaseStorage in Frameworks */ = {isa = PBXBuildFile; productRef = 0517F1FD2AE75DF700FD855A /* FirebaseStorage */; };
0517F2002AE75DF700FD855A /* FirebaseStorageCombine-Community in Frameworks */ = {isa = PBXBuildFile; productRef = 0517F1FF2AE75DF700FD855A /* FirebaseStorageCombine-Community */; };
0517F2032AE7685400FD855A /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0517F2022AE7685400FD855A /* AppDelegate.swift */; };
054BA0002B3A76AB00DC82A2 /* Router.swift in Sources */ = {isa = PBXBuildFile; fileRef = 054B9FFF2B3A76AB00DC82A2 /* Router.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand Down
43 changes: 43 additions & 0 deletions StudyFora/Core/Router/Router.swift
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)
}
}

0 comments on commit 40dabf4

Please sign in to comment.