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

Clicking on an incomplete link to a topic (/t/ID or /t/SLUG) from
another post could replace current history entry or create two: one for
the incomplete URL and another one for the correct one. Going back was
either impossible or took the user to a redirect loop, redirected back
to /t/ID which redirected them again to /t/SLUG/ID.
This commit is contained in:
Dan Ungureanu 2021-07-22 18:59:59 +03:00 committed by GitHub
parent 73e8183ffb
commit 27211ee7bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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);
},
});