com.vaadin.flow.router.NotFoundException:找不到给定导航目标的路线

发布于 2025-01-19 05:22:06 字数 5541 浏览 2 评论 0原文

我目前正在使用 vaadin v23。 我想导航到(更改视图/页面)到“仪表板”

默认 - 登录页面视图代码如下所示:

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"

处理导航到另一个页面/视图的代码如下所示:

ui.get().navigate(DashboardView::class.java, RouteParameters(Extras.USER_ID, RandomStringUtils.randomAlphabetic(10)))

执行后,这是我得到的:

原因:com.vaadin.flow.router.NotFoundException:找不到路由 对于给定的导航目标 'com.fd.jvmbackend.views.adminPanel.login.DashboardView' 和 参数'{​​extra_user_id=ElKbspkysb}'

DashboardView.kt 内容:

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)
    }
}

请告诉我错误在哪里。我做错了什么?景观-> DashboardView 使用 @Route 注解注册。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你在看孤独的风景 2025-01-26 05:22:06

看起来像dashboardView :: class.java被解释为文字Java字符串“ com.fd.jvmbackend.views.adminpanel.login.login.dashboard.dashboard.dashboardview”,而不是类对象,类对象,类对象ui.navigate的错误超载被调用。尝试传递路由字符串(AdminPanelRoute.dashboard)。

编辑:我注意,您还使用navigate的第二个参数传递路由参数。 DashboardView不接受路由参数,因此您应该删除这些参数。

Looks like DashboardView::class.java is interpreted as the literal Java String "com.fd.jvmbackend.views.adminPanel.login.DashboardView", not the class object, and the wrong overload of ui.navigate is called. Try passing the Route String (AdminPanelRoute.DASHBOARD) instead.

EDIT: I note you're also passing route parameters with the second parameter of navigate. DashboardView doesn't accept route parameters, so you should remove those.

煞人兵器 2025-01-26 05:22:06

导航是参数敏感的。这意味着如果您导航到带有参数的仪表板路线,它将找不到。从 UI.navigate 表达式中删除参数,或使用“dashboard/:id”等值声明 @Route。请参阅URL 模板文档

The navigation is paramater sensitiv. That means if you navigate to the dashboard Route with Parameters it will not be found. Remove the argument from your UI.navigate expression or declare your @Route with a value like "dashboard/:id". See the URL Template Docu.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文