You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The @elastic/apm-rum-react package supports React Router v6 where you define your routes in JSX via a BrowserRouter and a subsequent route tree with Routes. Thus leading to the (excellent) ApmRoute and ApmRoutes APIs in order to "register" your route with the APM service.
However, if an application wants to use the new data router syntax, these APIs won't work as there is no longer a Route or Routes element if you're using the createBrowserRouter API.
Here's my best guess on what the best options are if you want to use the new data router APIs:
createBrowserRouter paired with createRoutesFromElements and ApmRoute like so:
In my application, I've opted for option 2 since we prefer to use the object syntax over the JSX syntax for defining our routes.
Given what I've laid out:
Is this the correct approach or do you recommend something different?
Could their be an opportunity to better support the data router without having to register each individual route with either the ApmRoute syntax or the withTransaction syntax.
In the meantime I've created a light wrapper of withTransaction like so:
I think the ApmRoute type isn't available anymore anyway? Seems to have been removed. So the option 2 is the only way, without reimplementing ApmRoute. I'm doing the migration to data APIs also.
React Router v6.4 introduced new APIs for configuring your applications route tree.
The
@elastic/apm-rum-react
package supports React Router v6 where you define your routes in JSX via aBrowserRouter
and a subsequent route tree withRoutes
. Thus leading to the (excellent)ApmRoute
andApmRoutes
APIs in order to "register" your route with the APM service.However, if an application wants to use the new data router syntax, these APIs won't work as there is no longer a
Route
orRoutes
element if you're using thecreateBrowserRouter
API.Here's my best guess on what the best options are if you want to use the new data router APIs:
createBrowserRouter
paired withcreateRoutesFromElements
andApmRoute
like so:createBrowerRouter
paired with thewithTransaction
HOCIn my application, I've opted for option 2 since we prefer to use the object syntax over the JSX syntax for defining our routes.
Given what I've laid out:
ApmRoute
syntax or thewithTransaction
syntax.In the meantime I've created a light wrapper of
withTransaction
like so:Thanks for the great library!
The text was updated successfully, but these errors were encountered: