diff --git a/packages/nextjs/src/client/performance.ts b/packages/nextjs/src/client/performance.ts index 2212092d5045..0dd0b109408f 100644 --- a/packages/nextjs/src/client/performance.ts +++ b/packages/nextjs/src/client/performance.ts @@ -143,7 +143,8 @@ export function nextRouterInstrumentation( if (startTransactionOnLocationChange) { Router.events.on('routeChangeStart', (navigationTarget: string) => { - const matchedRoute = getNextRouteFromPathname(stripUrlQueryAndFragment(navigationTarget)); + const strippedNavigationTarget = stripUrlQueryAndFragment(navigationTarget); + const matchedRoute = getNextRouteFromPathname(strippedNavigationTarget); let transactionName: string; let transactionSource: TransactionSource; @@ -152,7 +153,7 @@ export function nextRouterInstrumentation( transactionName = matchedRoute; transactionSource = 'route'; } else { - transactionName = navigationTarget; + transactionName = strippedNavigationTarget; transactionSource = 'url'; } diff --git a/packages/nextjs/test/performance/client.test.ts b/packages/nextjs/test/performance/client.test.ts index 0b3ae0e7437e..cc0f212cbf18 100644 --- a/packages/nextjs/test/performance/client.test.ts +++ b/packages/nextjs/test/performance/client.test.ts @@ -231,6 +231,7 @@ describe('nextRouterInstrumentation', () => { ['/news', '/news', 'route'], ['/news/', '/news', 'route'], ['/some-route-that-is-not-defined-12332', '/some-route-that-is-not-defined-12332', 'url'], // unknown route + ['/some-route-that-is-not-defined-12332?q=42', '/some-route-that-is-not-defined-12332', 'url'], // unknown route w/ query param ['/posts/42', '/posts/[id]', 'route'], ['/posts/42/', '/posts/[id]', 'route'], ['/posts/42?someParam=1', '/posts/[id]', 'route'], // query params are ignored