Router should push to history if the state differs from the previous when the url is the same
See original GitHub issueπ bug report
Affected Package
The issue is caused by package @angular/routerIs this a regression?
I'm not sureDescription
When using a resolver to load a resource and the resource fails, trying to redirect the user to the same route they are currently on does not set the router's `state`.this.router.navigate(['route1'], { state: { resolveFailed: path } });
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Use case:
A table shows the user a list of items. The user requests to load a given item using the resolver, but the item no longer exists on the list. The API will return an error which requires preventing the user from navigating to the resourceβs page, but still showing an error message. Setting the state
on the navigation extras can be used exactly for this purpose.
π¬ Minimal Reproduction
Reproduced issue on Stackblitz
Steps:
- click on route1 button, text should say
Route 1 State: {"fromPage": "main", "navigationId": ...}
- click on route2 button, text should say
Route 2 State: {"fromPage": "main", "navigationId": ...}
- click again on route1 button
- click on route3 button, text should say
Route 2, State: { "resolveFailed": "https://api.example.com", "navigationId": ... }
- click on route1 button
- click on route2 button, text should say
Route 2 State: {"fromPage": "main", "navigationId": ...}
- click on route 3 button:
Text should say Route 2 State: {"resolveFailed": "https://api.example.com", "navigationId": ...}
Actual text displayed: Route 2 State: {"fromPage": "main", "navigationId": ...}
Explanation:
Route 3 has a resolver which connects to a resource that doesnβt exist, that in turn throws an error, caught by catchError
rxjs operator. The catchError redirects the user back to route2
.
- If the user asked to navigate to the route from route1, then the state will be set successfully, as seen in step 4.
- If the request was made from
route2
, then the user doesnβt effectively change route and the state doesnβt get set.
π Your Environment
Angular Version:
8.2.14
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (5 by maintainers)
Agree. Done.
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.