This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/routes/unknown.js
Kane York 4b8acce92b FIX: Check for permalinks before showing the 404 page
Limitations: the user profile "open external links in new tab setting" is
slightly broken for "External URL" permalinks.

Remove the copy from the admin permalinks page stating that this doesn't work.
2020-03-23 16:31:07 -07:00

23 lines
616 B
JavaScript

import { ajax } from "discourse/lib/ajax";
import DiscourseURL from "discourse/lib/url";
import DiscourseRoute from "discourse/routes/discourse";
export default DiscourseRoute.extend({
model(params, transition) {
const path = params.path;
return ajax("/permalink-check.json", {
data: { path }
}).then(results => {
if (results.found) {
// Avoid polluting the history stack for external links
transition.abort();
DiscourseURL.routeTo(results.target_url);
return "";
} else {
// 404 body HTML
return results.html;
}
});
}
});