apm-agent-rum-js icon indicating copy to clipboard operation
apm-agent-rum-js copied to clipboard

Cannot use ApmRoutes with react-router v7

Open immnk opened this issue 1 year ago • 2 comments

When using ApmRoutes with react-router package v7, I get this error

Image

package.json "react-router": "^7.2.0" "@elastic/apm-rum": "^5.16.0", "@elastic/apm-rum-react": "^2.0.2",

main.tsx

import { ApmRoutes } from '@elastic/apm-rum-react';

export function App() { return ( <ApmRoutes> </ApmRoutes> ); }

immnk avatar Mar 07 '25 09:03 immnk

@immnk hard to tell from the example you pasted but make sure you have the correct structure, you also need BrowserRouter as a wrapper, which seems to be missing based on your screenshot.

I was able to use the Elastic APM React agent w/ React Router 7.2.2, basic example below:

import { ApmRoutes } from "@elastic/apm-rum-react";
import { BrowserRouter, Route } from "react-router";

export const App = () => {
  return (
      <>
        <BrowserRouter>
          <ApmRoutes> // <-- replaces the "Routes" component from react-router
            <Route
              index
              path="/"
              element={<Home />}
            />
            <Route
              path="/settings"
              element={<Settings />}
            />
          </ApmRoutes>
        </BrowserRouter>
      </>
  );
};

rlueder avatar Apr 04 '25 19:04 rlueder

@immnk did the comment above help you to resolve the issue?

david-luna avatar Jun 12 '25 16:06 david-luna