remix-run / react-router

Declarative routing for React
https://reactrouter.com
MIT License
52.84k stars 10.23k forks source link

[Bug]: window hashchange event is not triggered on navigate() with createHashRouter #11220

Closed RakeshPawar closed 8 months ago

RakeshPawar commented 8 months ago

What version of React Router are you using?

6.20.0

Steps to Reproduce

I am new to react router , would appreciate some help here.

sandbox link Background-

I am working on vite+ react app as shell in micro-frontend , child micro-frontends also has its own routing and I am using 'hashchange' event to sync them together.

Expected Behavior

Should raise 'hashchange' event?

Actual Behavior

no event is raised. Event is raised if I use back or navigate(-1)

brophdawg11 commented 8 months ago

React Router uses history.pushState/history.replaceState under the hood for push/replace navigations which don't trigger hashchange events. Your best best to synchronize across these sub-apps is probably to use an effect to fire a custom event on useLocation changes