Skip to content

Commit 961629b

Browse files
committed
feat(core): 新增router
1 parent d3ee537 commit 961629b

File tree

5 files changed

+122
-0
lines changed

5 files changed

+122
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import React, { createElement } from 'react';
2+
import { Route } from 'react-router';
3+
4+
/**
5+
<CreateRouter basePath="/user" resource="user">
6+
<Create />
7+
</CreateRouter>;
8+
*/
9+
10+
export const CreateRouter = ({ basePath, resource, children }) => {
11+
if (!children) {
12+
return null;
13+
}
14+
15+
return (
16+
<Route
17+
path={`${basePath}/create`}
18+
render={props =>
19+
createElement(children, {
20+
basePath,
21+
...resource,
22+
...props,
23+
})
24+
}
25+
/>
26+
);
27+
};
28+
29+
export default CreateRouter;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import React, { createElement } from 'react';
2+
import { Route } from 'react-router';
3+
4+
/**
5+
<EditRouter basePath="/user" resource="user">
6+
<Show />
7+
</EditRouter>;
8+
*/
9+
10+
export const EditRouter = ({ basePath, resource, children }) => {
11+
if (!children) {
12+
return null;
13+
}
14+
15+
return (
16+
<Route
17+
path={`${basePath}/:id`}
18+
render={props =>
19+
createElement(children, {
20+
basePath,
21+
id: decodeURIComponent(props.match.params.id),
22+
...resource,
23+
...props,
24+
})
25+
}
26+
/>
27+
);
28+
};
29+
30+
export default EditRouter;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import React, { createElement } from 'react';
2+
import { Route } from 'react-router';
3+
4+
/**
5+
<ListRouter basePath="/user" resource="user">
6+
<Create />
7+
</ListRouter>;
8+
*/
9+
10+
export const ListRouter = ({ basePath, resource, children }) => {
11+
if (!children) {
12+
return null;
13+
}
14+
15+
return (
16+
<Route
17+
path={basePath}
18+
render={props =>
19+
createElement(children, {
20+
basePath,
21+
...resource,
22+
...props,
23+
})
24+
}
25+
/>
26+
);
27+
};
28+
29+
export default ListRouter;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import React, { createElement } from 'react';
2+
import { Route } from 'react-router';
3+
4+
/**
5+
<ShowRouter basePath="/user" resource="user">
6+
<Show />
7+
</ShowRouter>;
8+
*/
9+
10+
export const ShowRouter = ({ basePath, resource, children }) => {
11+
if (!children) {
12+
return null;
13+
}
14+
15+
return (
16+
<Route
17+
path={`${basePath}/:id/show`}
18+
render={props =>
19+
createElement(children, {
20+
basePath,
21+
id: decodeURIComponent(props.match.params.id),
22+
...resource,
23+
...props,
24+
})
25+
}
26+
/>
27+
);
28+
};
29+
30+
export default ShowRouter;

packages/core/src/router/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export * from './CreateRouter';
2+
export * from './EditRouter';
3+
export * from './ListRouter';
4+
export * from './ShowRouter';

0 commit comments

Comments
 (0)