I have a problem with navigation. Tab with corresp...
# kvision
i
I have a problem with navigation. Tab with corresponding route is not selected when page is loaded, see code and a screenshot in thread.
Copy code
Routing.init(useHash = false, root = "/")
val applicationState: MutableStateFlow<ApplicationState> = MutableStateFlow(ApplicationState.Route1)
routing
	.on("/", { applicationState.value = ApplicationState.Route1 })
	.on("/route1", { applicationState.value = ApplicationState.Route1 })
	.on("/route2", { applicationState.value = ApplicationState.Route2 })
	.resolve()
			
tabPanel {
	tab("Route1", route = "/")
	tab("Route2", route = "/route2")
}
Route 2
tab is not selected
r
Is this with kvision-routing-navigo-ng module and history api based routing?
i
Yes. Result is the same with
useHash = true
and path /#/route2
r
What if you remove manual routing (
on
calls). Does TabPanel routing work?
Perhaps you should add
strategy = Strategy.ALL
to the
init(...)
call. By default
Strategy.ONE
is used.
i
If I remove
on
it works as expected, with
strategy = Strategy.ALL
it works too. I didn't get why doesn't it work with
ONE
strategy? With
ONE
strategy
applicationState.value = ApplicationState.Route2
handler triggers updating my state, but only tab selection doesn't work
r
with the default strategy only the first matching route is executed
you have added manually the same handler kvision does internally for tabs
so there are two different
routing.on("/route1")
calls
i
OK, so I registered a handler for route, then each tab registers it's own handler, so with
Strategy.ONE
tab's handler never invokes. Thanks for your help 🙂 Do you think it would be useful to put this notice to this section https://kvision.gitbook.io/kvision-guide/3.-optional-ui-functionality-via-modules/js-routing#usage-with-panel?
r
I've added a note on this.
👍 1
🙏 1