diff --git a/packages/ra-core/src/routing/useCreatePath.spec.tsx b/packages/ra-core/src/routing/useCreatePath.spec.tsx
index 040ecdb9417..dafd834a0d1 100644
--- a/packages/ra-core/src/routing/useCreatePath.spec.tsx
+++ b/packages/ra-core/src/routing/useCreatePath.spec.tsx
@@ -1,15 +1,24 @@
import * as React from 'react';
import { render, screen } from '@testing-library/react';
-import { useCreatePath } from './useCreatePath';
+import { CreatePathType, useCreatePath } from './useCreatePath';
import { AtRoot, SubPath } from './useCreatePath.stories';
+import { Identifier } from '../types';
describe('useCreatePath', () => {
beforeEach(() => {
window.history.replaceState({}, '', '/');
});
- const UseCreatePath = ({ resource, type, id }: any) => {
+ const UseCreatePath = ({
+ resource,
+ type,
+ id,
+ }: {
+ resource: string;
+ type: CreatePathType;
+ id?: Identifier;
+ }) => {
const createPath = useCreatePath();
const path = createPath({ resource, type, id });
return
{path}
;
diff --git a/packages/ra-core/src/routing/useCreatePath.ts b/packages/ra-core/src/routing/useCreatePath.ts
index 1b38a4d3eb9..ab7ff9b1283 100644
--- a/packages/ra-core/src/routing/useCreatePath.ts
+++ b/packages/ra-core/src/routing/useCreatePath.ts
@@ -76,8 +76,11 @@ export const useCreatePath = () => {
);
};
+type AnyString = string & {};
+export type CreatePathType = 'list' | 'edit' | 'show' | 'create' | AnyString;
+
export interface CreatePathParams {
- type: string;
+ type: CreatePathType;
resource: string;
id?: Identifier;
}
diff --git a/packages/ra-core/src/routing/useRedirect.spec.tsx b/packages/ra-core/src/routing/useRedirect.spec.tsx
index ab813e3402a..fbbcdedf984 100644
--- a/packages/ra-core/src/routing/useRedirect.spec.tsx
+++ b/packages/ra-core/src/routing/useRedirect.spec.tsx
@@ -6,15 +6,22 @@ import { Routes, Route, useLocation } from 'react-router-dom';
import { createMemoryHistory } from 'history';
import { CoreAdminContext } from '../core';
-import { useRedirect } from './useRedirect';
+import { RedirectionSideEffect, useRedirect } from './useRedirect';
import { testDataProvider } from '../dataProvider';
+import { Identifier, RaRecord } from '../types';
const Redirect = ({
redirectTo,
resource = '',
- id = null,
- data = null,
- state = null,
+ id = undefined,
+ data = undefined,
+ state = undefined,
+}: {
+ redirectTo: RedirectionSideEffect;
+ resource?: string;
+ id?: Identifier;
+ data?: Partial;
+ state?: object;
}) => {
const redirect = useRedirect();
useEffect(() => {
@@ -89,6 +96,7 @@ describe('useRedirect', () => {
it('should support absolute URLs', () => {
const oldLocation = window.location;
+ // @ts-ignore
delete window.location;
// @ts-ignore
window.location = { href: '' };
diff --git a/packages/ra-core/src/routing/useRedirect.ts b/packages/ra-core/src/routing/useRedirect.ts
index a1af02a5eca..78d9068794c 100644
--- a/packages/ra-core/src/routing/useRedirect.ts
+++ b/packages/ra-core/src/routing/useRedirect.ts
@@ -4,7 +4,7 @@ import { parsePath } from 'history';
import { Identifier, RaRecord } from '../types';
import { useBasename } from './useBasename';
-import { useCreatePath } from './useCreatePath';
+import { CreatePathType, useCreatePath } from './useCreatePath';
type RedirectToFunction = (
resource?: string,
@@ -13,7 +13,7 @@ type RedirectToFunction = (
state?: object
) => To;
-export type RedirectionSideEffect = string | false | RedirectToFunction;
+export type RedirectionSideEffect = CreatePathType | false | RedirectToFunction;
/**
* Hook for Redirection Side Effect