PluginProbe
Tableberg – Simple Gutenberg Table Block / 1.1.5
Tableberg – Simple Gutenberg Table Block v1.1.5
1.1.5 1.1.4 1.1.3 1.1.2 1.1.1 1.1.0 1.0.5 1.0.4 1.0.3 1.0.2 1.0.1 trunk 0.0.2 0.2.1 0.3.2 0.3.3 0.4.1 0.5.0 0.5.1 0.5.2 0.5.3 0.5.4 0.5.5 0.5.6 0.5.7 All 42 releases
tableberg / admin / src / components / Router.jsx

Router.jsx in Tableberg – Simple Gutenberg Table Block 1.1.5, at admin/src/components/Router.jsx

49 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import React, { useEffect, useState } from "react";
2 import Route from "../inc/Route";
3
4 /**
5 * Router for different menu content.
6 *
7 * Router children components should be Route components. Else those who are not will be ignored.
8 *
9 * If no route matches, the last route will be shown. It can be used as 404 page.
10 *
11 * @param {Object} props component properties
12 * @param {Array<Route>} props.routes routes array
13 * @param {string} props.currentRoutePath current route path
14 */
15 function Router({ routes, currentRoutePath }) {
16 const [CurrentRouteContent, setCurrentRouteContent] = useState(null);
17
18 /**
19 * useEffect hook.
20 */
21 useEffect(() => {
22 const currentRoute = routes.find(route => {
23 return route.getPath() === currentRoutePath;
24 });
25
26 if (currentRoute) {
27 setCurrentRouteContent(currentRoute.getElement());
28 } else {
29 const lastRoute = routes[routes.length - 1];
30 setCurrentRouteContent(lastRoute.getElement());
31 }
32 }, [currentRoutePath, routes]);
33
34 return (
35 <div
36 className={"tableberg-router-content-wrapper"}
37 data-route-path={currentRoutePath}
38 key={currentRoutePath}
39 >
40 {CurrentRouteContent}
41 </div>
42 );
43 }
44
45 /**
46 * @module Router
47 */
48 export default Router;
49