Skip to content

fix(routing): redirect to home with warning for invalid network URLs#305

Merged
AugustoL merged 3 commits intoopenscan-explorer:devfrom
AugustoL:fix/invalid-network-routing
Mar 12, 2026
Merged

fix(routing): redirect to home with warning for invalid network URLs#305
AugustoL merged 3 commits intoopenscan-explorer:devfrom
AugustoL:fix/invalid-network-routing

Conversation

@AugustoL
Copy link
Collaborator

Description

When navigating to an invalid network segment (e.g., /undefined/txs, /foo/blocks), the app silently fell back to Ethereum Mainnet and fetched incorrect data. Now it validates the network param and redirects to the home page with a warning notification.

Related Issue

Closes #290

Type of Change

  • Bug fix
  • New feature
  • Documentation update
  • Refactoring
  • Performance improvement
  • Other

Changes Made

  • Created ValidateNetwork layout route component that checks the :networkId param against enabled networks
  • If the network is invalid, redirects to / (home) and shows a warning notification: "The network X is not recognized..."
  • Wrapped all EVM :networkId routes with ValidateNetwork using React Router's layout route pattern (<Outlet />)
  • Added i18n keys for the warning message in both English and Spanish

Screenshots (if applicable)

N/A — test by navigating to /#/undefined/txs or /#/foo/blocks

Checklist

  • I have run npm run format:fix and npm run lint:fix
  • I have run npm run typecheck with no errors
  • I have run tests with npm run test:run
  • I have tested my changes locally
  • I have updated documentation if needed
  • My code follows the project's architecture patterns

Additional Notes

The ValidateNetwork component uses isNetworkEnabled() from the networks config, which checks both that the network exists and that it's included in the REACT_APP_OPENSCAN_NETWORKS env filter (if set). This means disabled networks will also redirect with a warning.

Invalid network segments like /undefined/txs silently fell back to
Ethereum mainnet, showing misleading data. Now validates the network
param against enabled networks and redirects to the home page with
a warning notification when the network is not recognized.

Closes openscan-explorer#290
@github-actions
Copy link

github-actions bot commented Mar 12, 2026

🚀 Preview: https://pr-305--openscan.netlify.app
📝 Commit: 2ad6ba34f720d81d85712c939ec00af7ee698a79

… under navbar

Warning notifications now have a yellow background tint and border.
Notifications are positioned sticky under the navbar instead of fixed
overlapping it, with rounded borders (12px).
…icate

Notification container is now fixed at top 70px (under navbar), centered,
max 520px wide. Warning style uses yellow tint. Added ref guard to prevent
duplicate notifications from React Strict Mode.
Copy link
Collaborator

@josealoha666 josealoha666 left a comment

Choose a reason for hiding this comment

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

Reviewed the routing diff and it looks good to me. Wrapping the dynamic :networkId routes in ValidateNetwork is a clean fix for #290, and using isNetworkEnabled(networkId) keeps invalid or disabled networks from silently falling back to mainnet. I also like that the warning is localized and only fires once before redirecting home.

@AugustoL AugustoL merged commit e82b161 into openscan-explorer:dev Mar 12, 2026
4 of 7 checks passed
@AugustoL AugustoL mentioned this pull request Mar 16, 2026
10 tasks
Copy link
Collaborator

@josealoha666 josealoha666 left a comment

Choose a reason for hiding this comment

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

Quick review: I skimmed the diff and did not find a clear blocker. Leaving a comment-only review for now.

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