UNPKG

@sentry/react-native

Version:
64 lines 2.16 kB
/** * Shared helpers for reading Expo Router's internal router store. * * Used by: * - {@link expoRouterIntegration} to attach the current route to the idle * navigation span via {@link RouteOverride}. * - {@link wrapExpoRouterErrorBoundary} to attach the current route to errors * surfaced through Expo Router's per-route `ErrorBoundary`. */ /** * Returns Expo Router's internal router store, or `null` if `expo-router` is * not installed or the build does not expose the expected module path. */ export function tryGetExpoRouterStore() { var _a; try { // eslint-disable-next-line @typescript-eslint/no-var-requires const mod = require('expo-router/build/global-state/router-store'); return (_a = mod === null || mod === void 0 ? void 0 : mod.store) !== null && _a !== void 0 ? _a : null; } catch (_b) { return null; } } /** * Builds a templated pathname from Expo Router's `segments`. Grouping segments * (e.g. `(tabs)`, `(auth)`) are stripped because they do not appear in the URL. */ export function buildExpoRouterTemplatedPath(segments) { if (!segments || segments.length === 0) { return '/'; } const filtered = segments.filter(s => !(s.startsWith('(') && s.endsWith(')'))); return filtered.length === 0 ? '/' : `/${filtered.join('/')}`; } /** * Reads the current route from Expo Router's store and normalizes it. Returns * `undefined` if the store is not reachable or `getRouteInfo` throws. */ export function getCurrentExpoRouterRouteInfo() { var _a; const store = tryGetExpoRouterStore(); if (!store) { return undefined; } let info; try { info = (_a = store.getRouteInfo) === null || _a === void 0 ? void 0 : _a.call(store); } catch (_b) { return undefined; } if (!info) { return undefined; } return { templatedPath: buildExpoRouterTemplatedPath(info.segments), pathname: info.pathname, pathnameWithParams: info.pathnameWithParams, params: info.params, segments: info.segments, }; } //# sourceMappingURL=expoRouterStore.js.map