Bug: Improve back navigation logic in ItemComponent#5170
Conversation
There was a problem hiding this comment.
Pull request overview
Improves “Back to results” navigation on item pages by persisting an allowed previous URL in session storage, so the back button remains correct across refreshes and different navigation entry points (including /home).
Changes:
- Added generic session storage URL helpers to
RouteService. - Updated
ItemComponentto validate/store previous URLs and fall back to session storage when route history isn’t usable; expanded allowed previous routes to include/home. - Updated/added unit tests and stubs to cover the revised behavior.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/app/core/services/route.service.ts | Adds sessionStorage helpers for storing/retrieving URLs. |
| src/app/item-page/simple/item-types/shared/item.component.ts | Stores/uses a validated previous URL with a session fallback; allows /home. |
| src/app/item-page/simple/item-types/shared/item.component.spec.ts | Adds tests for /home back navigation and “prefer route over stale session” behavior. |
| src/app/core/testing/route-service.stub.ts | Extends the RouteService stub with session helper methods for tests. |
| src/app/item-page/simple/item-types/publication/publication.component.spec.ts | Updates RouteService mocks to include new session helper methods. |
| src/app/item-page/simple/item-types/untyped-item/untyped-item.component.spec.ts | Updates RouteService mocks to include new session helper methods. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
QA testing performed (no code review). Works as expected:
|
|
Hi @milanmajchrak, |
|
@milanmajchrak : Could you resolve the merge conflict on this PR so that we are able to move this forward? Thanks! |
8eaff6c to
c6f6ae2
Compare
@tdonohue Thank you for the reminder. The merge conflicts have been resolved and the branch has been cleaned up into a single commit. |
tdonohue
left a comment
There was a problem hiding this comment.
👍 Thanks @milanmajchrak ! I've verified this works well & the code looks good to me. I'm also going to flag this for possible backport to dspace-9_x because I agree it's a usability improvement.
|
Backport failed for Please cherry-pick the changes locally and resolve any conflicts. git fetch origin dspace-9_x
git worktree add -d .worktree/backport-5170-to-dspace-9_x origin/dspace-9_x
cd .worktree/backport-5170-to-dspace-9_x
git switch --create backport-5170-to-dspace-9_x
git cherry-pick -x c6f6ae28b565598857c04e08df0b97e5c009752c |
|
@milanmajchrak : It looks like the automated backport to 9.x failed (see above). If you'd like to see this in 9.x, please create a separate PR against our |
Bug: Improve back navigation logic in ItemComponent
|
Backported to 9.x in #5631 |
References
Original author: @amadulhaxxani
Description
Improves the "Back to results" button logic on item pages by adding session storage as a fallback for the previous URL. This ensures the back button works correctly across page refreshes and prevents stale navigation when users visit items from different contexts (e.g. homepage vs. collection browse).
Instructions for Reviewers
List of changes in this PR:
storeUrlInSession()andgetUrlFromSession()generic helper methods toRouteServicefor persisting URLs in session storageItemComponentto store the previous URL in session storage and fall back to it when the route-based previous URL is not a valid navigation target/hometo the list of allowed previous routes so the back button appears when navigating from the homepagepickAllowedPrevious()helper method for cleaner logicback()method to use the stored URL directly instead of re-subscribing to the observableroute-service.stub.ts,publication.component.spec.ts,untyped-item.component.spec.ts, anditem.component.spec.tsHow to test:
Checklist
This checklist provides a reminder of what we are going to look for when reviewing your PR. You do not need to complete this checklist prior creating your PR (draft PRs are always welcome).
However, reviewers may request that you complete any actions in this list if you have not done so. If you are unsure about an item in the checklist, don't hesitate to ask. We're here to help!
mainbranch of code (unless it is a backport or is fixing an issue specific to an older branch).npm run lintnpm run check-circ-deps)package.json), I've made sure their licenses align with the DSpace BSD License based on the Licensing of Contributions documentation.