UNPKG

@grafana/faro-react

Version:

Faro package that enables easier integration in projects built with React.

28 lines 1.23 kB
import { EVENT_ROUTE_CHANGE, globalObject } from '@grafana/faro-web-sdk'; import { api } from '../../dependencies'; import { NavigationType } from '../types'; import { isInitialized } from './routerDependencies'; import { getRouteFromLocation } from './utils'; /** * To use with React Router 6.4 data APIs. */ export function withFaroRouterInstrumentation(router) { let lastRoute = {}; router.subscribe((state) => { var _a, _b; const navigationType = state.historyAction; const location = state.location; const routes = router.routes; if (isInitialized && (navigationType === NavigationType.Push || navigationType === NavigationType.Pop)) { const route = getRouteFromLocation(routes, location); const url = (_a = globalObject.location) === null || _a === void 0 ? void 0 : _a.href; api.pushEvent(EVENT_ROUTE_CHANGE, Object.assign({ toRoute: route, toUrl: (_b = globalObject.location) === null || _b === void 0 ? void 0 : _b.href }, lastRoute)); lastRoute = { fromRoute: route, fromUrl: url, }; } }); return router; } //# sourceMappingURL=withFaroRouterInstrumentation.js.map