File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed
static/app/utils/reactRouter6Compat Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change 1- import { Children , isValidElement } from 'react' ;
1+ import { Children , isValidElement , useEffect } from 'react' ;
22import {
33 Navigate ,
44 type NavigateProps ,
55 Outlet ,
66 type RouteObject ,
77 useOutletContext ,
88} from 'react-router-dom' ;
9+ import * as Sentry from '@sentry/react' ;
910
1011import { USING_CUSTOMER_DOMAIN } from 'sentry/constants' ;
1112import replaceRouterParams from 'sentry/utils/replaceRouterParams' ;
@@ -75,6 +76,21 @@ interface RedirectProps extends Omit<NavigateProps, 'to'> {
7576 */
7677function Redirect ( { to, ...rest } : RedirectProps ) {
7778 const params = useParams ( ) ;
79+ const routes = useRoutes ( ) ;
80+
81+ // Capture sentry error for this redirect. This will help us understand if we
82+ // have redirects that are unused or used too much.
83+ useEffect ( ( ) => {
84+ const routePath = routes
85+ . map ( route => route . path ?? '' )
86+ . filter ( path => path !== '' )
87+ . join ( '/' ) ;
88+
89+ Sentry . captureMessage ( 'Redirect route used' , {
90+ level : 'info' ,
91+ tags : { routePath} ,
92+ } ) ;
93+ } , [ routes ] ) ;
7894
7995 return < Navigate to = { replaceRouterParams ( to , params ) } { ...rest } /> ;
8096}
You can’t perform that action at this time.
0 commit comments