自定义“页面不存在”页面

Hi community!

I am trying to customize the “Page doesn’t exist” page. It currently shows the words " Oops! That page doesn’t exist or is private.". However, I would like to replace this with an image instead. Is there any way to do this? I was thinking of using plugin-outlets but there does not seem to be one for it. Thanks in advance.

4 个赞

Maybe we should have a plugin outlet for this @eviltrout?

4 个赞

Unfortunately it’s not simple since there are two versions of that page. One is generated server side and one is generated client side, depending on the error. We could add an outlet to the client side page but you wouldn’t always see it. Also I should note that page is used for all exceptions so you’d have to differentiate between a network error, a 500 error, a 404, etc.

4 个赞

只是想确认一下,目前是否有办法解决这个问题?如果可能的话,我们也希望能修改该页面。

它没有变化,抱歉。

1 个赞

明白了,谢谢您的快速回复。

我能够使用一点 Javascript 来自定义消息:

window.addEventListener("DOMContentLoaded", function(){
    document.querySelector('.page-not-found .title').innerHTML = "新的消息在这里";
});

该脚本替换了“糟糕!该页面不存在或已设为私有”所在位置的 HTML。我还没有尝试过,但理论上,您可以添加 HTML 来渲染图片。

2 个赞