简体   繁体   中英

React-router need a way to detect route change

I search a way to detect route change / leave. I try the exemple https://github.com/rackt/react-router/blob/master/docs/guides/advanced/ConfirmingNavigation.md but i can't make it work in my project.

http://pastebin.com/TXW71gmV

I need to get the next route too, so the route argument onLeave doesn't provide anything.

I know i can detect the URL with document.location in the onLeave function, but i want something more consistant or built in.

Does anybody can help me with this?

Thank you

The route leave hook does indeed get called with the next location, when the transition is triggered by React Router.

If you're actually leaving the page outright, you're not going to see this, because it will just be hitting the "before unload" hook, from which the router can't build the next location, since it's not something the router is managing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM