Description
Describe the bug
The Angular Router can get into a infinite loop in Firefox when Router.navigateByUrl
is invoked and the token from the IdP contains an error.
I believe others are not seeing this issue in the masses because it requires the IdP redirection location to first land on an "confirmation page", this page then redirects the app to the proper application route, based on success or failure. When failure occurs the window.location
contains a hash in the URL. Which causes the Angular router to invoke popstate
immediately after the navigateByUrl
routing has completed.
What is Occurring:
- Angular Application bootstraps and
tryLogin
is invoked onapp.component
- Token is parsed by oauth2 lib, and it contains an error
handleLoginError
is invoked - Within this method an attempt is made to clear
location.hash
if configured and setlocation.hash = ''
(code) - In Firefox only!
location.hash = ''
will actually add hash to the URL!
- Error bubbles out from oauth2 lib and
app.component
callsRouter.navigateByUrl
- Routing successful
popstate
occurs in Angular router redirecting the app back toapp.component
tryLogin
is again attempted byapp.component
; process repeats (GOTO step 2)
Expected behavior
No infinite routing loops 😄
Additional context
Firefox adds a hash to the URL if you attempt to clear it with an empty string. This can be fixed by first checking if location.hash
contains a hash before trying to clear it with an empty string.
I believe fixing this would address other issues that have workarounds:
#493
#408
This issue also describes the problems using location.hash
and Angular Router
#622