why TCA coordinator's routeAction working only once?

141 Views Asked by At

Now I made my project by using SwiftUI and TCA and TCA coordinator.

I made root view and root View have a tree tab. last tab is profile tab. in profile tab when click the profile detail button, it go to the profile detail view

Now it is working but only once. I touch the back button and came back to profile tab and click button again, It is not working.

struct Coordinator: ReducerProtocol {
    struct State: Equatable, IndexedRouterState {
        var routes: [Route<Screen.State>]
        
        static let initialState = State(
            routes: [.root(.login(.init()), embedInNavigationView: true)]
        )
        
        
    }
    
    enum Action: IndexedRouterAction {
        case routeAction(Int, action: Screen.Action)
        case updateRoutes([Route<Screen.State>])
    }
    
    var body: some ReducerProtocol<State, Action> {
        return Reduce<State, Action> { state, action in
            switch action {
            case .routeAction(_, action: .login(.tabAsGuestButton)):
                state.routes.push(.root(.init()))
                return .none
            
            case .routeAction(_, action: .login(.successLogin)):
                state.routes.presentCover(.root(.init()))
                return .none
                
            case .routeAction(_, action: .root(.profileTab(.gotoLoginView))):
                    state.routes.popToRoot()
                return .none
            
            case .routeAction(_, action: .root(.profileTab(.tabEditProfileButton))):
                state.routes.push(.editProfile(.init()))
                return .none
            case .updateRoutes(let routes):
               state.routes = routes
               return .none
                
            default:
                    break
            }
            return .none
        }.forEachRoute {
            Screen()
        }
    }
}

0

There are 0 best solutions below