Skip to content

navigation.subscribe callback called twice #187

Open
@kmkr

Description

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!
    });
  },
);

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions