First, I'm sorry for asking a question here. I know this is not a place to ask but I couldn't find the proper way to implement it on docs.
i'm using HashRouter instead of BrowserRoute since I'm managing my react app on AWS s3 which is static hosting.
Now I want to integrate Google Analytics into my app and need to detect Route changes. I looked into documents which react-router team provides but couldn't get one. I know there is a way to detect changes using withRouter with BrowserRouter. but I'm using HashRouter.
Can anyone know how to do it with HashRouter?
The <HashRouter> is essentially the same as the <BrowserRouter>. Aside from how locations map to URIs, the only real API difference is that <HashRouter> locations can't have state.
There are a number of ways to do this, you just have to subscribe to your history object to be informed of location changes. If you want to do this through React, you can use the <OnUpdate> from my rrc package. You can also just use that as reference and write your own.
In previous version I was doing like this:
import { hashHistory } from 'react-router'
hashHistory.listen(() => {
window.scrollTo(0, 0);
});
to move view to the top when useing smooth-scrool
Is there any equivalent in v4?
Most helpful comment
In previous version I was doing like this:
import { hashHistory } from 'react-router'hashHistory.listen(() => { window.scrollTo(0, 0); });to move view to the top when useing smooth-scrool
Is there any equivalent in v4?