@treely/strapi-slices 7.15.2 → 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/README.md +2 -0
- package/dist/__mocks__/next/navigation.d.ts +7 -0
- package/dist/__mocks__/next/router.d.ts +1 -0
- package/dist/slices/Redirect/Redirect.d.ts +7 -0
- package/dist/slices/Redirect/index.d.ts +2 -0
- package/dist/strapi-slices.cjs.development.js +241 -283
- 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 +241 -283
- package/dist/strapi-slices.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/SliceRenderer/SliceRenderer.tsx +5 -0
- package/src/slices/Redirect/Rediect.test.tsx +30 -0
- package/src/slices/Redirect/Redirect.tsx +18 -0
- package/src/slices/Redirect/index.ts +3 -0
package/package.json
CHANGED
|
@@ -42,6 +42,7 @@ import Locale from '../../models/Locale';
|
|
|
42
42
|
import { ContextProvider } from '../ContextProvider';
|
|
43
43
|
import Timeline from '../../slices/Timeline';
|
|
44
44
|
import Events from '../../slices/Events';
|
|
45
|
+
import Redirect from '../../slices/Redirect';
|
|
45
46
|
import { AnalyticsFunction } from '../ContextProvider/ContextProvider';
|
|
46
47
|
|
|
47
48
|
export interface CustomSliceProps {
|
|
@@ -316,6 +317,10 @@ export const SliceRenderer = ({
|
|
|
316
317
|
return (
|
|
317
318
|
<Events key={`${slice.__component}-${slice.id}`} slice={slice} />
|
|
318
319
|
);
|
|
320
|
+
case 'sections.redirect':
|
|
321
|
+
return (
|
|
322
|
+
<Redirect key={`${slice.__component}-${slice.id}`} slice={slice} />
|
|
323
|
+
);
|
|
319
324
|
default:
|
|
320
325
|
if (CustomSlice) {
|
|
321
326
|
return (
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render } from '../../test/testUtils';
|
|
3
|
+
import { mergeDeep } from '../../utils/mergeDeep';
|
|
4
|
+
import { replaceSpy, useRouter } from '../../../__mocks__/next/router';
|
|
5
|
+
import Redirect from '.';
|
|
6
|
+
import { RedirectProps } from './Redirect';
|
|
7
|
+
|
|
8
|
+
const defaultProps: RedirectProps = {
|
|
9
|
+
slice: {
|
|
10
|
+
url: 'https://redirect.com',
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const setup = (props = {}) => {
|
|
15
|
+
const combinedProps = mergeDeep(defaultProps, props);
|
|
16
|
+
render(<Redirect {...combinedProps} />);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
describe('The Redirect component', () => {
|
|
20
|
+
afterEach(() => {
|
|
21
|
+
replaceSpy.mockRestore();
|
|
22
|
+
useRouter.mockRestore();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('calls the redirect URL when rendering', () => {
|
|
26
|
+
setup();
|
|
27
|
+
|
|
28
|
+
expect(replaceSpy).toHaveBeenCalledWith('https://redirect.com');
|
|
29
|
+
});
|
|
30
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { useRouter } from 'next/router';
|
|
2
|
+
import React, { useEffect } from 'react';
|
|
3
|
+
|
|
4
|
+
export interface RedirectProps {
|
|
5
|
+
slice: {
|
|
6
|
+
url: string;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const Redirect = ({ slice }: RedirectProps): JSX.Element => {
|
|
11
|
+
const router = useRouter();
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
// When using `replace`, the current browser history entry will be replaced
|
|
14
|
+
router.replace(slice.url);
|
|
15
|
+
}, [slice.url]);
|
|
16
|
+
|
|
17
|
+
return <></>;
|
|
18
|
+
};
|