From 8eb61de1cd03e6deafe794621747069b5b259560 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Tue, 11 Jan 2022 13:10:46 +0000 Subject: [PATCH] FIX: Handling of `/p/###` URLs within Ember (#15536) --- .../javascripts/discourse/app/routes/post.js | 19 ++++++++----------- .../discourse/tests/acceptance/topic-test.js | 7 +++++++ 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/app/assets/javascripts/discourse/app/routes/post.js b/app/assets/javascripts/discourse/app/routes/post.js index 8d8bb40d66d..4fcfdba5a6c 100644 --- a/app/assets/javascripts/discourse/app/routes/post.js +++ b/app/assets/javascripts/discourse/app/routes/post.js @@ -1,17 +1,14 @@ import DiscourseRoute from "discourse/routes/discourse"; -import { ajax } from "discourse/lib/ajax"; +import { inject as service } from "@ember/service"; export default DiscourseRoute.extend({ - beforeModel({ params, _discourse_anchor }) { - return ajax(`/p/${params.post.id}`).then((t) => { - const transition = this.transitionTo( - "topic.fromParamsNear", - t.slug, - t.id, - t.current_post_number - ); + router: service(), - transition._discourse_anchor = _discourse_anchor; - }); + model(params) { + return this.store.find("post", params.id); + }, + + afterModel(post) { + this.router.transitionTo(post.url); }, }); diff --git a/app/assets/javascripts/discourse/tests/acceptance/topic-test.js b/app/assets/javascripts/discourse/tests/acceptance/topic-test.js index 0bdfa70f49f..5caa7455f2e 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/topic-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/topic-test.js @@ -588,6 +588,7 @@ acceptance("Navigating between topics", function (needs) { firstPost.cooked += `\nLink 2`; firstPost.cooked += `\nLink 3`; firstPost.cooked += `\nLink 3`; + firstPost.cooked += `\nLink to Post`; server.get("/t/280.json", () => helper.response(topicResponse)); server.get("/t/280/:post_number.json", () => @@ -617,4 +618,10 @@ acceptance("Navigating between topics", function (needs) { await click("a.diff-topic-slugless-post"); assert.ok(currentURL().includes("/281")); }); + + test("clicking post URLs", async function (assert) { + await visit("/t/-/280"); + await click("a.by-post-id"); + assert.ok(currentURL().includes("/280")); + }); });