!我可以通过主题 HTML 中的脚本来处理 404 页面……
我让 404 页面将浏览器窗口重新加载到“丢失”的 URL,这将命中服务器端。它奏效了!我看到的唯一缺点是重定向很明显,而且对于任何真正的 404,您都会被带出应用程序(丢失侧边栏/标题)。
<script type="text/discourse-plugin" version="0.8">
api.onPageChange((url, title) => {
const router = api.container.lookup('service:router');
var is404 = document.getElementsByClassName("page-not-found");
if (is404.length) {
const params = new URLSearchParams(router.currentRoute.queryParams).toString();
let q = "";
if (params){ q = "?"+params; }
window.location.replace(window.location.origin + url + q);
}
});
</script>