From 961629b7333836b09a62cae58a09bebe182031b2 Mon Sep 17 00:00:00 2001 From: stbui Date: Wed, 18 Sep 2019 23:39:59 +0800 Subject: [PATCH] =?UTF-8?q?feat(core):=20=E6=96=B0=E5=A2=9Erouter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/src/router/CreateRouter.tsx | 29 ++++++++++++++++++++++ packages/core/src/router/EditRouter.tsx | 30 +++++++++++++++++++++++ packages/core/src/router/ListRouter.tsx | 29 ++++++++++++++++++++++ packages/core/src/router/ShowRouter.tsx | 30 +++++++++++++++++++++++ packages/core/src/router/index.ts | 4 +++ 5 files changed, 122 insertions(+) create mode 100644 packages/core/src/router/CreateRouter.tsx create mode 100644 packages/core/src/router/EditRouter.tsx create mode 100644 packages/core/src/router/ListRouter.tsx create mode 100644 packages/core/src/router/ShowRouter.tsx create mode 100644 packages/core/src/router/index.ts diff --git a/packages/core/src/router/CreateRouter.tsx b/packages/core/src/router/CreateRouter.tsx new file mode 100644 index 0000000..8234c68 --- /dev/null +++ b/packages/core/src/router/CreateRouter.tsx @@ -0,0 +1,29 @@ +import React, { createElement } from 'react'; +import { Route } from 'react-router'; + +/** + + +; + */ + +export const CreateRouter = ({ basePath, resource, children }) => { + if (!children) { + return null; + } + + return ( + + createElement(children, { + basePath, + ...resource, + ...props, + }) + } + /> + ); +}; + +export default CreateRouter; diff --git a/packages/core/src/router/EditRouter.tsx b/packages/core/src/router/EditRouter.tsx new file mode 100644 index 0000000..26b8c74 --- /dev/null +++ b/packages/core/src/router/EditRouter.tsx @@ -0,0 +1,30 @@ +import React, { createElement } from 'react'; +import { Route } from 'react-router'; + +/** + + +; + */ + +export const EditRouter = ({ basePath, resource, children }) => { + if (!children) { + return null; + } + + return ( + + createElement(children, { + basePath, + id: decodeURIComponent(props.match.params.id), + ...resource, + ...props, + }) + } + /> + ); +}; + +export default EditRouter; diff --git a/packages/core/src/router/ListRouter.tsx b/packages/core/src/router/ListRouter.tsx new file mode 100644 index 0000000..26cc67e --- /dev/null +++ b/packages/core/src/router/ListRouter.tsx @@ -0,0 +1,29 @@ +import React, { createElement } from 'react'; +import { Route } from 'react-router'; + +/** + + +; + */ + +export const ListRouter = ({ basePath, resource, children }) => { + if (!children) { + return null; + } + + return ( + + createElement(children, { + basePath, + ...resource, + ...props, + }) + } + /> + ); +}; + +export default ListRouter; diff --git a/packages/core/src/router/ShowRouter.tsx b/packages/core/src/router/ShowRouter.tsx new file mode 100644 index 0000000..195c90f --- /dev/null +++ b/packages/core/src/router/ShowRouter.tsx @@ -0,0 +1,30 @@ +import React, { createElement } from 'react'; +import { Route } from 'react-router'; + +/** + + +; + */ + +export const ShowRouter = ({ basePath, resource, children }) => { + if (!children) { + return null; + } + + return ( + + createElement(children, { + basePath, + id: decodeURIComponent(props.match.params.id), + ...resource, + ...props, + }) + } + /> + ); +}; + +export default ShowRouter; diff --git a/packages/core/src/router/index.ts b/packages/core/src/router/index.ts new file mode 100644 index 0000000..bb0072f --- /dev/null +++ b/packages/core/src/router/index.ts @@ -0,0 +1,4 @@ +export * from './CreateRouter'; +export * from './EditRouter'; +export * from './ListRouter'; +export * from './ShowRouter';