core-api: add NotFoundPage to FlatRoutes

This commit is contained in:
Patrik Oldsberg
2021-02-21 23:02:34 +01:00
parent 904280dd72
commit c7fd1c6a2e
+11 -1
View File
@@ -14,8 +14,9 @@
* limitations under the License.
*/
import { ReactNode, Children, isValidElement, Fragment } from 'react';
import React, { ReactNode, Children, isValidElement, Fragment } from 'react';
import { useRoutes } from 'react-router-dom';
import { useApp } from '../app';
type RouteObject = {
path: string;
@@ -71,6 +72,15 @@ type FlatRoutesProps = {
};
export const FlatRoutes = (props: FlatRoutesProps): JSX.Element | null => {
const app = useApp();
const { NotFoundErrorPage } = app.getComponents();
const routes = createRoutesFromChildren(props.children);
// TODO(Rugvip): Possibly add a way to skip this, like a noNotFoundPage prop
routes.push({
element: <NotFoundErrorPage />,
path: '/*',
});
return useRoutes(routes);
};