diff --git a/public/app/features/alerting/unified/components/notification-policies/Policy.test.tsx b/public/app/features/alerting/unified/components/notification-policies/Policy.test.tsx
index dfff88a463a..1e3a0af1583 100644
--- a/public/app/features/alerting/unified/components/notification-policies/Policy.test.tsx
+++ b/public/app/features/alerting/unified/components/notification-policies/Policy.test.tsx
@@ -1,10 +1,10 @@
-import { render, renderHook, screen, within } from '@testing-library/react';
+import { renderHook, screen, within } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { first, noop } from 'lodash';
-import { Router } from 'react-router-dom';
-import { CompatRouter } from 'react-router-dom-v5-compat';
+import { Routes, Route } from 'react-router-dom-v5-compat';
+import { render } from 'test/test-utils';
-import { config, locationService } from '@grafana/runtime';
+import { config } from '@grafana/runtime';
import { contextSrv } from 'app/core/core';
import {
AlertmanagerGroup,
@@ -345,13 +345,17 @@ describe('Policy', () => {
});
});
+// Doesn't matter which path the routes use, it just needs to match the initialEntries history entry to render the element
const renderPolicy = (element: JSX.Element) =>
render(
-
-
- {element}
-
-
+
+ {element}} />
+ ,
+ {
+ historyOptions: {
+ initialEntries: ['/'],
+ },
+ }
);
const eq = MatcherOperator.equal;
diff --git a/public/app/features/alerting/unified/components/receivers/ReceiversSection.tsx b/public/app/features/alerting/unified/components/receivers/ReceiversSection.tsx
index a8c9a2591e8..5b3fb521e8c 100644
--- a/public/app/features/alerting/unified/components/receivers/ReceiversSection.tsx
+++ b/public/app/features/alerting/unified/components/receivers/ReceiversSection.tsx
@@ -1,6 +1,6 @@
import { css, cx } from '@emotion/css';
import * as React from 'react';
-import { Link } from 'react-router-dom';
+import { Link } from 'react-router-dom-v5-compat';
import { useToggle } from 'react-use';
import { GrafanaTheme2 } from '@grafana/data';
diff --git a/public/app/features/alerting/unified/components/rule-editor/alert-rule-form/AlertRuleForm.tsx b/public/app/features/alerting/unified/components/rule-editor/alert-rule-form/AlertRuleForm.tsx
index 8805b40cf1e..57c385d856e 100644
--- a/public/app/features/alerting/unified/components/rule-editor/alert-rule-form/AlertRuleForm.tsx
+++ b/public/app/features/alerting/unified/components/rule-editor/alert-rule-form/AlertRuleForm.tsx
@@ -1,7 +1,7 @@
import { css } from '@emotion/css';
import { useCallback, useEffect, useMemo, useState } from 'react';
import { FormProvider, SubmitErrorHandler, UseFormWatch, useForm } from 'react-hook-form';
-import { useParams } from 'react-router-dom';
+import { useParams } from 'react-router-dom-v5-compat';
import { GrafanaTheme2 } from '@grafana/data';
import { config, locationService } from '@grafana/runtime';
@@ -82,7 +82,7 @@ export const AlertRuleForm = ({ existing, prefill }: Props) => {
const routeParams = useParams<{ type: string; id: string }>();
const ruleType = translateRouteParamToRuleType(routeParams.type);
- const uidFromParams = routeParams.id;
+ const uidFromParams = routeParams.id || '';
const [showDeleteModal, setShowDeleteModal] = useState(false);
diff --git a/public/app/features/alerting/unified/components/rule-editor/alert-rule-form/simplifiedRouting/SimplifiedRuleEditor.test.tsx b/public/app/features/alerting/unified/components/rule-editor/alert-rule-form/simplifiedRouting/SimplifiedRuleEditor.test.tsx
index 70dbaf94fdf..c78fb2df968 100644
--- a/public/app/features/alerting/unified/components/rule-editor/alert-rule-form/simplifiedRouting/SimplifiedRuleEditor.test.tsx
+++ b/public/app/features/alerting/unified/components/rule-editor/alert-rule-form/simplifiedRouting/SimplifiedRuleEditor.test.tsx
@@ -1,5 +1,5 @@
import { ReactNode } from 'react';
-import { Route } from 'react-router-dom';
+import { Routes, Route } from 'react-router-dom-v5-compat';
import { ui } from 'test/helpers/alertingRuleEditor';
import { clickSelectOption } from 'test/helpers/selectOptionInTest';
import { render, screen, waitForElementToBeRemoved, userEvent } from 'test/test-utils';
@@ -157,7 +157,10 @@ describe('Can create a new grafana managed alert using simplified routing', () =
function renderSimplifiedRuleEditor() {
return render(
-
+
+ } />
+ } />
+
,
{ historyOptions: { initialEntries: ['/alerting/new/alerting'] } }
);
diff --git a/public/app/features/alerting/unified/components/rules/CloneRule.tsx b/public/app/features/alerting/unified/components/rules/CloneRule.tsx
index cb0d0cdbc80..4e12142a156 100644
--- a/public/app/features/alerting/unified/components/rules/CloneRule.tsx
+++ b/public/app/features/alerting/unified/components/rules/CloneRule.tsx
@@ -1,6 +1,5 @@
import { forwardRef, useState } from 'react';
-import { useLocation } from 'react-router-dom';
-import { Navigate } from 'react-router-dom-v5-compat';
+import { Navigate, useLocation } from 'react-router-dom-v5-compat';
import { Button, ConfirmModal } from '@grafana/ui';
import { RuleIdentifier } from 'app/types/unified-alerting';
diff --git a/public/test/helpers/alertingRuleEditor.tsx b/public/test/helpers/alertingRuleEditor.tsx
index b40cdb66d64..e07a335fad9 100644
--- a/public/test/helpers/alertingRuleEditor.tsx
+++ b/public/test/helpers/alertingRuleEditor.tsx
@@ -1,4 +1,4 @@
-import { Route } from 'react-router-dom';
+import { Routes, Route } from 'react-router-dom-v5-compat';
import { render } from 'test/test-utils';
import { byRole, byTestId, byText } from 'testing-library-selector';
@@ -35,11 +35,17 @@ export const ui = {
};
export function renderRuleEditor(identifier?: string, recording = false) {
- return render(, {
- historyOptions: {
- initialEntries: [
- identifier ? `/alerting/${identifier}/edit` : `/alerting/new/${recording ? 'recording' : 'alerting'}`,
- ],
- },
- });
+ return render(
+
+ } />
+ } />
+ ,
+ {
+ historyOptions: {
+ initialEntries: [
+ identifier ? `/alerting/${identifier}/edit` : `/alerting/new/${recording ? 'recording' : 'alerting'}`,
+ ],
+ },
+ }
+ );
}