@treely/strapi-slices 7.16.0 → 7.16.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/__mocks__/next/router.d.ts +1 -0
- package/dist/strapi-slices.cjs.development.js +2 -2
- package/dist/strapi-slices.cjs.development.js.map +1 -1
- package/dist/strapi-slices.cjs.production.min.js +1 -1
- package/dist/strapi-slices.cjs.production.min.js.map +1 -1
- package/dist/strapi-slices.esm.js +2 -2
- package/dist/strapi-slices.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/slices/Redirect/Rediect.test.tsx +4 -7
- package/src/slices/Redirect/Redirect.tsx +3 -2
package/package.json
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { render } from '../../test/testUtils';
|
|
3
3
|
import { mergeDeep } from '../../utils/mergeDeep';
|
|
4
|
-
import {
|
|
4
|
+
import { replaceSpy, useRouter } from '../../../__mocks__/next/router';
|
|
5
5
|
import Redirect from '.';
|
|
6
6
|
import { RedirectProps } from './Redirect';
|
|
7
|
-
import { RedirectType } from 'next/navigation';
|
|
8
7
|
|
|
9
8
|
const defaultProps: RedirectProps = {
|
|
10
9
|
slice: {
|
|
@@ -19,15 +18,13 @@ const setup = (props = {}) => {
|
|
|
19
18
|
|
|
20
19
|
describe('The Redirect component', () => {
|
|
21
20
|
afterEach(() => {
|
|
22
|
-
|
|
21
|
+
replaceSpy.mockRestore();
|
|
22
|
+
useRouter.mockRestore();
|
|
23
23
|
});
|
|
24
24
|
|
|
25
25
|
it('calls the redirect URL when rendering', () => {
|
|
26
26
|
setup();
|
|
27
27
|
|
|
28
|
-
expect(
|
|
29
|
-
'https://redirect.com',
|
|
30
|
-
RedirectType.replace
|
|
31
|
-
);
|
|
28
|
+
expect(replaceSpy).toHaveBeenCalledWith('https://redirect.com');
|
|
32
29
|
});
|
|
33
30
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { useRouter } from 'next/router';
|
|
1
2
|
import React, { useEffect } from 'react';
|
|
2
|
-
import { RedirectType, redirect } from 'next/navigation';
|
|
3
3
|
|
|
4
4
|
export interface RedirectProps {
|
|
5
5
|
slice: {
|
|
@@ -8,9 +8,10 @@ export interface RedirectProps {
|
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
export const Redirect = ({ slice }: RedirectProps): JSX.Element => {
|
|
11
|
+
const router = useRouter();
|
|
11
12
|
useEffect(() => {
|
|
12
13
|
// When using `replace`, the current browser history entry will be replaced
|
|
13
|
-
|
|
14
|
+
router.replace(slice.url);
|
|
14
15
|
}, [slice.url]);
|
|
15
16
|
|
|
16
17
|
return <></>;
|