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

Added onRouteUpdate in versioned_docs 👨‍💻 #3444

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions website/docs/docusaurus-core.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,26 @@ const MyComponent = () => {
};
```

### `onRouteUpdate({location})`

If the current rendering environment is on client i.e. `ExecutionEnvironment.canUseDOM === true`, then `onRouteUpdate({location})` updates the Google Analytics plugin
by setting the page value to current path, inorder to measure the number of views one had for a particular page on the website.
Recommended for Single-page Applications.

Usage example:

```jsx {2,5,6,7}
import React from 'react';
import {onRouteUpdate} from '@docusaurus/useGlobalData';

const MyComponent = () => {
const location = { pathname:'./example.html' };

onRouteUpdate({location});
return <div>Page value set to {location.pathname}</div>;
};
```

## Modules

### `ExecutionEnvironment`
Expand Down