FIX: Client should be able to route ID-less topic URLs (#15697)

The topic ID portion of the topic URL is optional in Discourse as long as the topic slug is unique across the site. If you navigate to a topic without the ID in the URL, Discourse will redirect you to the canonical version of the URL that includes the ID.

However, we have a now regression where the client app doesn't correctly handle ID-less topic URLs displays an error message when the user clicks on such URL. The regression was introduced b537d591b3 when we switched from `DiscourseURL.routeTo` to using Ember's router to perform the redirecting to the canonical version of the URL, but the problem is that the canonical version comes from the server and it contains the hostname which the Ember router doesn't understand because it expects a relative URL.

This PR fixes the problem by constructing a relative URL that contains the topic slug and ID and passing that to the Ember route.
This commit is contained in:
Osama Sayegh 2022-01-24 23:19:35 +03:00 committed by GitHub
parent a5cb6ab8a0
commit a742952c8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -9,7 +9,9 @@ export default DiscourseRoute.extend({
if (params.slugOrId.match(ID_CONSTRAINT)) {
return { url: `/t/topic/${params.slugOrId}` };
} else {
return Topic.idForSlug(params.slugOrId);
return Topic.idForSlug(params.slugOrId).then((data) => {
return { url: `/t/${data.slug}/${data.topic_id}` };
});
}
},