Smart Disconnect - Exclude Pages with React Router

Hi,

The mixmax smart disconnect GitHub page explains how to ignore this disconnect on certain pages using FlowRouter.

Is there a way to do this with React Router?

From the main disconnect function in startup/client:

// ..........

const disconnectIfHidden = () => {
  removeDisconnectTimeout()

  if (document.hidden) { // and if ['path1', 'path2'...].indexOf(window.location.pathname) !== -1, or with a Regex.
    createDisconnectTimeout()
  } else {
    Meteor.reconnect()
  }
}

In order to do it with a router, you would probably need to listen:

history.listen(location => { ... })
// If the page is not in a page set, start the disconnect function.

history is no longer part of the React-Router. So … I am not aware of any feasible way to do the disconnection based on the router. So either listen to the window.location or the history.location

1 Like

@paulishca

Thanks for the advice! I’ve only just got round to properly testing it but it’s working perfectly.

I’ve even created a PR so that the disconnectVoids functionality can be used by everyone who isn’t using FlowRouter.

The PR is here if you’re interested.

I also included some extra documentation in the README to explain how to easily check when a disconnect or connect occurs.

:slight_smile:

1 Like

For future reference, the mixmax:smart-disconnect package now includes support for projects that do not use Flow Router (package version 0.0.5).

There are also some examples on how to check when there is a disconnection / reconnection.