Repository navigation
fix(router): keep search and notifications in history when opening a result - #603
Conversation
…result Links from search results and notifications carry no slug, so the canonical route guard redirected them with replace: true. vue-router then turned the whole click into a replace, dropping the Search or Notifications entry, and Back skipped past it. Only replace on deep links; in-app clicks stay a push.
|
| query: to.query, | ||
| hash: to.hash, | ||
| replace: true, | ||
| ...(isInAppNavigation ? {} : { replace: true }), |
There was a problem hiding this comment.
History behavior lacks coverage. The redirect now depends on whether navigation began in the app, but no test covers that distinction. Please test that Back returns to Search or Notifications after opening a slugless result, and that a cold-load canonical redirect replaces its URL. Without those checks, either history behavior could regress unnoticed.
Prompt To Fix With AI
This is a comment left during a code review.
Path: frontend/src/router.ts
Line: 939
Comment:
**History behavior lacks coverage.** The redirect now depends on whether navigation began in the app, but no test covers that distinction. Please test that Back returns to Search or Notifications after opening a slugless result, and that a cold-load canonical redirect replaces its URL. Without those checks, either history behavior could regress unnoticed.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Problem
Opening a result from Search or a Notification and pressing Back skipped the Search/Notifications page and went to whatever was open before it.
Cause
Search results and notifications link to a discussion without its slug. The canonical-route guard (
getCanonicalContentRouteinrouter.ts) resolves the slug and redirects withreplace: true. When a guard redirects withreplace: true, vue-router applies it to the whole navigation, so the user's click became a replace and the Search/Notifications history entry was overwritten.Fix
Only force
replace: truefor deep links (first load, refresh, pasted URL), where the non-canonical URL shouldn't stay in history. In-app clicks keep their own push/replace behaviour, so the redirect adds the slug without dropping the previous page.