Skip to content

Conversation

@aryan-gupta7
Copy link

Description

This PR fixes the infinite redirect loop that occurs when a user attempts to switch the application language.

The core of the issue was located in lib/utils/router.ts within the customRoute function. Previously, the code updated the location.hash by unconditionally prepending a forward slash to the match.hashString. Since match.hashString often already contained a leading slash, this resulted in malformed URLs (e.g., //de/map). These malformed paths failed to satisfy the router's regex requirements, causing the application to fail to recognize the state and trigger another reload, thus starting the loop.

The Fix:
The logic now checks for the existence of a leading slash in match.hashString before constructing the final URL hash.

Motivation and Context

  • Fixes: Issue #284
  • Problem: Users were unable to change languages without being trapped in a series of infinite page reloads.

How Has This Been Tested?

  • Manual Test: Verified that switching languages now correctly reloads the page once with a properly formatted URL (e.g., #/de/map) and correctly initialized translations.
  • Build Test: Ran npm run build to confirm the changes compile correctly within the project structure.

Checklist:

  • My code follows the code style of this project. (CI will test it anyway and also needs approval)
  • My change requires a change to the documentation.
    • I have updated the documentation accordingly.

…e the main issue was that in `/libs/utils/router.ts` in `customUrl` the `location.hash` was adding a `/` without checking if it already exists or not, which failed the url from passing the regex, ending up in a redirect loop. the fix checks if the `/` exists before making the final Url.
making code cleaner

Co-authored-by: Florian Maurer <[email protected]>
@maurerle
Copy link
Member

when choosing en with en as default, another # is added:

image

Can you fix this as well?

@aryan-gupta7
Copy link
Author

I just checked it, yeah this happens when you try to change language to the current language.
I think I can fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants