Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

react-router browserHistory removeListen?

I subscribe to route changes with

browserHistory.listen(fn)

but how can I unsubscribe?

I have tried assigning to listen null, but it complains about not being a function.

like image 979
Fez Vrasta Avatar asked Feb 07 '23 04:02

Fez Vrasta


1 Answers

The return from listen is a function that will unsubscribe the listener when called. So just save it for later:

var unlisten = browserHistory.listen(fn)

// ...some time later...
unlisten()
like image 187
Tim Dorr Avatar answered Feb 09 '23 17:02

Tim Dorr