Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

navigation.subscribe callback called twice #187

Open
kmkr opened this issue May 28, 2020 · 0 comments
Open

navigation.subscribe callback called twice #187

kmkr opened this issue May 28, 2020 · 0 comments

Comments

@kmkr
Copy link
Contributor

kmkr commented May 28, 2020

We use the navigation.subscribe method to log page views to Google Analytics. The callback we pass to the subscribe method runs twice every time a user clicks an internal link on the page, and we end up sending double page views. Any idea why that happens ?

Here's how we use it, slightly simplified:

// ...
const navigation = createBrowserNavigation({
  context: rootNaviContext,
  url: window.location.href,
  routes,
});
hydrate(
  <Router navigation={navigation}>
    <Web>
      <Body />
    </Web>
  </Router>,
  document.getElementById('root'),
  () => {
    logGaPageView(route.url.href); // logs initial page view
    navigation.subscribe(route => {
       logGaPageView(route.url.href); // logs subsequent page views twice!
    });
  },
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant