Skip to content

A platform for community discussion. Free, open, simple.

FIX: Ensure browser history contains correct URLs (#13367)

Dan Ungureanu27211ee7bbf6
diff --git a/app/assets/javascripts/discourse/app/routes/topic-by-slug-or-id.js b/app/assets/javascripts/discourse/app/routes/topic-by-slug-or-id.js
index 0cfe24473fe..f2805aedd1a 100644
--- a/app/assets/javascripts/discourse/app/routes/topic-by-slug-or-id.js
+++ b/app/assets/javascripts/discourse/app/routes/topic-by-slug-or-id.js
@@ -12,6 +12,17 @@ export default DiscourseRoute.extend({
},
afterModel(result) {
- DiscourseURL.routeTo(result.url, { replaceURL: true });
+ // Using { replaceURL: true } to replace the current incomplete URL with
+ // the complete one is working incorrectly.
+ //
+ // Let's consider an example where the user is at /t/-/1. If they click on
+ // a link to /t/2 the expected behavior is to take the user to /t/2 that
+ // will redirect to /t/-/2 and generate a history with two entries: /t/-/1
+ // followed by /t/-/2.
+ //
+ // When { replaceURL: true } is present, the history contains a single
+ // entry /t/-/2. This suggests that `afterModel` is called in the context
+ // of the referrer replacing its entry with the new one.
+ DiscourseURL.routeTo(result.url);
},
});