ich habe ein Problem, das ich lösen möchte, stoße dabei aber auf Schwierigkeiten.
Das Verhalten, das ich mit einer benutzerdefinierten Route erreichen möchte, entspricht im Wesentlichen dem, was man sieht, wenn man auf einen nicht existierenden Topic-Link klickt. Wenn man auf einen Link zu einem nicht existierenden Topic klickt, wird eine 404-Seite angezeigt. Klickt man dann auf die Zurück-Taste des Browsers, wird man zum Topic zurückgeleitet, von dem man gekommen ist.
Bei meiner benutzerdefinierten Route stelle ich jedoch ein anderes Verhalten fest. Wenn ich mich auf meiner benutzerdefinierten Route befinde, wird ein JSON-Datensatz vom Backend abgerufen. Ist dieser JSON-Datensatz nicht vorhanden, gibt der Controller eine 404-Seite zurück. EmberJS nimmt dies wahr und leitet auf www.my-discourse-server.com/404 weiter. Bisher also alles gut. Wenn ich jedoch auf die Zurück-Taste drücke, gelange ich zurück auf die nicht existierende Seite, die erneut eine 404 zurückgibt, und ich befinde mich wieder auf der /404-Seite.
Ich versuche kurz zu skizzieren, wie der Code aussieht. Meine Route:
Wenn dies eine 404 zurückgibt, wird dies von Discourse abgefangen und gemäß /discourse/app/assets/javascripts/discourse/routes/application.js.es6 auf ‘exception-unknown’ umgelenkt.
Im Grunde möchte ich dem Benutzer eine 404-Seite anzeigen, ohne dass die URL auf /404 umgeleitet wird.
I actually created PRs for the procourse-static-pages plugin recently. Glad you removed the Licensing, since I think more people can benefit from this plugin.
When I make a post, linking to a non-existing procourse-static-page, I see the same behaviour as I described. So when you click the link in the post, Discourse opens that URL and receives a 404 from the controller (as intended). However, the frontend then redirects you to /404. Meaning that if you go back, you again hit the non-existing route which again redirects you to the /404.
We’re still dealing with this problem, and I think your plugin can also benefit from a solution.
The Static Pages plugin simply follows the core Discourse process. I try to stick to the “the Discourse way” as much as I can.
Since this seems to be the way it works in core, you would need to write an acceptable PR for the team. But I can’t speak to whether or not they would accept it. There may be a valid reason for redirecting to a 404 page as opposed to leaving the URL.
I agree that it seems to be “the Discourse way”. However, when I link to a non-existing topic/post, Discourse does not redirect to a 404 page, but simply renders one without redirecting. So there seem to be multiple ways of handling this.