Skip to content

Commit 121c727

Browse files
committed
Add 404 page with redirections
1 parent 7ddbcd7 commit 121c727

File tree

1 file changed

+92
-0
lines changed
  • packages/react-renderer-demo/src/pages

1 file changed

+92
-0
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import React, { useEffect, useState } from 'react';
2+
import { useRouter } from 'next/router';
3+
4+
const rerouting = {
5+
'/renderer/get-started': '/introduction',
6+
'/renderer/installation': '/installation',
7+
'/renderer/development-setup': '/development-setup',
8+
'/renderer/component-mapping': '/mappers/custom-mapper',
9+
'/renderer/renderer-api': '/components/renderer',
10+
'/renderer/component-api': '/mappers/component-api',
11+
'/renderer/form-template': '/components/form-template',
12+
'/renderer/unmounting': '/schema/clear-on-unmount',
13+
'/renderer/initialize-mount': '/schema/initialize-on-mount',
14+
'/renderer/data-types': '/schema/data-types',
15+
'/renderer/file-input': '/mappers/file-input',
16+
'/renderer/cleared-value': '/schema/cleared-value',
17+
'/renderer/field-provider': '/components/field-provider',
18+
'/renderer/action-mapper': '/mappers/action-mapper',
19+
'/renderer/dynamic-fields': '/components/field-array',
20+
'/renderer/schema-validator': '/mappers/schema-validator-mapper',
21+
'/renderer/condition': '/schema/introduction#condition',
22+
'/renderer/validators': '/schema/introduction#validate'
23+
};
24+
25+
const validatorHashMapper = {
26+
'#requiredvalidator': 'required-validator',
27+
'#lengthvalidators': 'length-validator',
28+
'#numbervaluevalidators': 'number-value-validator',
29+
'#patternvalidators': 'pattern-validator',
30+
'#urlvalidators': 'url-validator',
31+
'#customfunction': 'custom-validator',
32+
'#asyncvalidator': 'async-validator',
33+
'#customvalidatormapper': 'validator-mapper',
34+
'#recordlevelvalidation': 'record-level-validation',
35+
'#overwritingdefaultmessages': 'overwriting-default-message'
36+
};
37+
38+
const conditionHashMapper = {
39+
'#schema': 'condition-schema',
40+
'#or': 'or',
41+
'#and': 'and',
42+
'#not': 'not',
43+
'#sequence': 'condition-sequence',
44+
'#nesting': 'condition-nesting',
45+
'#is': 'is',
46+
'#isempty': 'is-empty',
47+
'#isnotempty': 'is-not-empty',
48+
'#pattern': 'pattern',
49+
'#notmatch': 'not-match',
50+
'#conditionalactions': 'condition-actions',
51+
'#set': 'condition-set',
52+
'#visible': 'condition-visible',
53+
'#example': 'complex-condition-example'
54+
};
55+
56+
const Custom404 = () => {
57+
const { push, asPath } = useRouter();
58+
const [loading, setLoading] = useState(false);
59+
60+
useEffect(() => {
61+
const hashPart = asPath.match(/#.*/);
62+
const hash = hashPart ? hashPart[0] : '';
63+
const pathname = asPath.replace(/(#|\?)+.*/, '');
64+
65+
if (asPath.includes('/component-example/')) {
66+
setLoading(true);
67+
push(asPath.replace('/component-example/', '/mappers/'));
68+
} else if (asPath.startsWith('/renderer/condition#') && conditionHashMapper[hash]) {
69+
setLoading(true);
70+
push(`/schema/${conditionHashMapper[hash]}`);
71+
} else if (asPath.startsWith('/renderer/validators#') && validatorHashMapper[hash]) {
72+
setLoading(true);
73+
push(`/schema/${validatorHashMapper[hash]}`);
74+
} else if (rerouting[pathname]) {
75+
setLoading(true);
76+
push(`${rerouting[pathname]}${hash}`);
77+
}
78+
}, []);
79+
80+
return (
81+
<React.Fragment>
82+
<h1>404 - Page Not Found</h1>
83+
{loading ? (
84+
<div>Redirecting to new address...</div>
85+
) : (
86+
<div>No page found. It is possible that the page was moved. Please use the navigation or search bar to find the page manually.</div>
87+
)}
88+
</React.Fragment>
89+
);
90+
};
91+
92+
export default Custom404;

0 commit comments

Comments
 (0)