如果 Url 在播放框架中无效,则重定向到错误页面。 1.25?

redirect to error page, if Url is invalid in play-framework. 1.25?

如果用户输入了无效的网址,我该如何重定向到错误页面。现在,在无效的情况下 URL play 会告诉我路线。

这些路线都试过了,顺序是:

   Not found
    GET /log

    These routes have been tried, in this order :


    GET       /@documentation/cheatsheet/{category}             PlayDocumentation.cheatSheet
        GET       /@documentation/modules/{module}/files/{name}     PlayDocumentation.file
        GET       /@documentation/modules/{module}/images/{name}    PlayDocumentation.image
        GET       /@documentation/modules/{module}/{id}             PlayDocumentation.page
        GET       /@documentation/files/{name}                      PlayDocumentation.file
        GET       /@documentation/images/{name}                     PlayDocumentation.image
        GET       /@documentation/{id}                              PlayDocumentation.page
        GET       /@documentation/?                                 PlayDocumentation.index
        GET       /public/                                          staticDir:public

出于多种原因,我确实想向用户显示路线。我怎样才能重定向到错误页面?

您可以修改提供的 app/views/errors/404。html 以提供不同的 404 视图。

路由列表应该只在 DEV 模式下显示,以便于调试。在 PROD 模式下,用户应该只看到 'Not Found'.

或者,您可以在自定义插件 (https://www.playframework.com/documentation/1.2.5/api/play/PlayPlugin.html) 中实施 afterActionInvocation() 以检查响应状态代码 404,然后重定向到完全不同的路由。