Skip to content

Conversation

SakshiKekre
Copy link
Collaborator

@SakshiKekre SakshiKekre commented Sep 19, 2025

Fixes #196

Implemented country-based URL routing to support multi-country functionality:

  • Modified Router structure to include /:countryId prefix for all routes
  • Added useCurrentCountry() hook to get country ID from URL params
  • Updated Sidebar navigation to dynamically include country prefix in all internal paths
  • All routes now follow pattern: /:countryId/[page] (e.g., /us/reports, /uk/simulations)

[EDIT] Updates since last review

Fixed country routing validation issue

Issue/Bug: Invalid paths like /configurations were incorrectly accepted as country codes and router would not redirect/navigate to country path.

Changes made:

  1. Added loader-based validation - Created validateCountryLoader that validates country parameters at the router level before components render
  2. Removed duplicate validation - Simplified useCurrentCountry hook to trust the loader's validation, removing redundant checks
  3. Proper redirect handling - Invalid countries now redirect to default country (US) while preserving the rest of the URL path
  4. Test coverage - Added tests for the new loader with proper fixtures following project conventions

Technical details:

  • Router now uses a loader to validate :countryId parameter against valid country list
  • Invalid routes like /configurations redirect to /us
  • Routes with invalid countries like /invalid/policies redirect to /us/policies
  • Hook no longer validates (Single Responsibility Principle) - it trusts the loader did its job
  • All tests updated to reflect new validation flow

Copy link
Collaborator

@anth-volk anth-volk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this @SakshiKekre. I have a few questions in here and mostly nits.

@SakshiKekre
Copy link
Collaborator Author

@anth-volk Thanks for the review. I have made changes based on your comments + bug fix (please see PR description for more).

Copy link
Collaborator

@anth-volk anth-volk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this @SakshiKekre. My main takeaway here: I really don't think we should be using loaders if we can avoid it. I think the code as it is is probably fine, but I wouldn't be surprised if down the road, we added something and literally rendered a white screen for a perceptible amount of time.

Skipped loader approach due to potential delayed rendering
Test malicious inputs including SQL injection, XSS, and path traversal
Copy link
Collaborator

@anth-volk anth-volk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move with this. If we find ourselves adding too many components that don't fit inside the layout component we have, we may want to modify.

@SakshiKekre SakshiKekre merged commit b79efe5 into main Sep 24, 2025
4 checks passed
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.

Configure React Router to use country IDs
2 participants