first of all thanks for attention and your help, so...
in my app I have router from where I log and logout user
@main
struct JobMatchApp: App {
@StateObject private var vm = RouterViewModel()
var body: some Scene {
WindowGroup {
NavigationStack {
Router()
}
.environmentObject(vm)
}
}
}
and from my Router I check if user is logged or not
struct Router: View {
EnvironmentObject var routerVM: RouterViewModel
var body: some View {
VStack {
if routerVM.isUserLoggedIn {
TabbarView()
} else {
LoginView()
}
}
.overlay {
if routerVM.isLoading {
VStack {
ProgressView()
.tint(.mintGreen)
.scaleEffect(1.5)
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(.deepNavy)
}
}
}
}
like this it works in tabbar and login perfectly, but somewhere I use NavigationLink it not works any more. for example from view where I go with NavigationLink logout function doesn't work any more. but when I press back button user is logged out and I go to LoginView(), but not automatically I need to press back button. as I said it works perfectly where I dont use NavigationLink or new NavigationStack.
NavigationLink {
ProfileSettings().toolbar(.hidden)
} label: {
Image(systemName: "gearshape")
.renderingMode(.template)
.resizable()
.frame(width: 24, height: 24)
.foregroundStyle(.mintGreen)
}
any help?
Routeryou should be using@EnvironmentObject var routerVM: RouterViewModel. In addition,...somewhere I use NavigationLink it not works any more, where do you use this, how do you call this, how do you pass theRouterViewModelto this? Show a minimal reproducible code that produces your issue, see: minimal code.TabBarViewandLoginView(if required). This will simplify thenavigationDestinationmodifier, and makes your app more modular, making the (valid) assumption, that a Login Scene and a TabBar Scene is completely different, not necessarily requiring a NavigationStack at all.