I am currently using vaadin v23. I want to navigate to (change view / page) to "Dashboard"
Default - login page view code looks like this:
package com.fd.jvmbackend.views.adminPanel.login import com.fd.jvmbackend.extensions.isNull import com.fd.jvmbackend.views.AdminPanelRoute import com.fd.jvmbackend.views.BaseView import com.fd.jvmbackend.views.Extras import com.vaadin.flow.component.AttachEvent import com.vaadin.flow.component.DetachEvent import com.vaadin.flow.component.Text import com.vaadin.flow.component.Unit import com.vaadin.flow.component.button.Button import com.vaadin.flow.component.html.Label import com.vaadin.flow.component.notification.Notification import com.vaadin.flow.router.* import kotlinx.coroutines.flow.collect import kotlinx.coroutines.launch import org.apache.commons.lang3.RandomStringUtils import java.util.concurrent.TimeUnit @Route(value = AdminPanelRoute.LOGIN) @PageTitle("Login | FD CMS") class LoginView() : BaseView() { private val TAG = "LoginView" private var viewModel: LoginViewModel? = null override fun onAttach(attachEvent: AttachEvent?) { super.onAttach(attachEvent) viewModel = LoginViewModel() val label = Label("Welcome.") val loginField = getLoginTextField("Login", "ex: mike", true, true) val passwordField = getPasswordField("Password", "ex. myLongPassword", true, true, true) val button = Button("Log in with credentials") button.setWidth(15F, Unit.PERCENTAGE) button.addClickListener { event -> viewModel?.onLoginClicked(loginField.value, passwordField.value) } add(label) add(loginField) add(passwordField) add(button) collectorsJob = lifecycleScope.launch { launch { viewModel?.getPageTitle()?.collect { value -> println("$TAG -> getPageTitle -> ${value}") ui.get().access { ui.get().page.setTitle(value) } } } launch { viewModel?.getErrorText()?.collect { value -> if(value.isNull()){ return@collect } ui.get().access { notification?.close() notification = Notification.show(value,TimeUnit.SECONDS.toMillis(5).toInt(),Notification.Position.BOTTOM_CENTER) } } } launch { viewModel?.getIsLoading()?.collect { value -> ui.get().access { if (value) { progressDialog = getIndeterminateProgressDialog("Loading", "please wait") progressDialog?.open() } else { progressDialog?.close() progressDialog = null } } ui.get().access { loginField.isEnabled = !value } ui.get().access { passwordField.isEnabled = !value } ui.get().access { button.isEnabled = !value } } } launch { viewModel?.getNavigationRouterLink()?.collect { value -> if(value.isNull()){ return@collect } ui.get().access { ui.get().navigate( DashboardView::class.java, RouteParameters(Extras.USER_ID, RandomStringUtils.randomAlphabetic(10)) ) } } } } } override fun onDetach(detachEvent: DetachEvent?) { viewModel?.onCleared() viewModel = null super.onDetach(detachEvent) } } AdminPanelRoute.LOGIN = "login", AdminPanelRoute.DASHBOARD = "dashboard"
Code which handles navigating to another page/view looks like this:
ui.get().navigate(DashboardView::class.java, RouteParameters(Extras.USER_ID, RandomStringUtils.randomAlphabetic(10))) After execution this is what I get:
Caused by: com.vaadin.flow.router.NotFoundException: No route found for the given navigation target 'com.fd.jvmbackend.views.adminPanel.login.DashboardView' and parameters '{extra_user_id=ElKbspkysb}'
DashboardView.kt contents:
package com.fd.jvmbackend.views.adminPanel.login import com.fd.jvmbackend.util.ResourceHandler import com.fd.jvmbackend.views.AdminPanelRoute import com.vaadin.flow.component.AttachEvent import com.vaadin.flow.component.DetachEvent import com.vaadin.flow.component.applayout.AppLayout import com.vaadin.flow.component.applayout.DrawerToggle import com.vaadin.flow.component.html.Image import com.vaadin.flow.component.html.Label import com.vaadin.flow.router.PageTitle import com.vaadin.flow.router.Route @Route(value = AdminPanelRoute.DASHBOARD) @PageTitle("Dashboard | FD CMS") class DashboardView:AppLayout() { private val TAG = "DashboardView" val label = Label("Secret message -> ") override fun onAttach(attachEvent: AttachEvent?) { super.onAttach(attachEvent) } override fun onDetach(detachEvent: DetachEvent?) { super.onDetach(detachEvent) } } Please tell me where is the mistake. What am I doing wrong ? The view -> DashboardView is registered with @Route annotation.