@lxzy/code-snippet 0.0.11 → 0.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lxzy/code-snippet",
3
- "version": "0.0.11",
3
+ "version": "0.0.13",
4
4
  "files": [
5
5
  "*",
6
6
  "!dist",
package/routes/menu.ts CHANGED
@@ -5,6 +5,12 @@ export default [
5
5
  component: 'home',
6
6
  icon: 'smile',
7
7
  },
8
+ {
9
+ path: '/login',
10
+ name: '登录',
11
+ component: 'login',
12
+ layout: false,
13
+ },
8
14
  {
9
15
  path: '/activityCenter',
10
16
  name: '活动中心',
package/src/App.tsx CHANGED
@@ -1,5 +1,5 @@
1
1
  import React, { Suspense, lazy } from 'react';
2
- import { Switch, Route, Redirect } from 'react-router-dom';
2
+ import { Switch, Route, Redirect, useHistory, useLocation } from 'react-router-dom';
3
3
  import { Router } from 'react-router-dom';
4
4
  import history from '@/umi';
5
5
  import BasicLayout from '@/layouts/index';
@@ -21,6 +21,28 @@ const loadComponent = (path) => {
21
21
  return componentCache[path];
22
22
  };
23
23
 
24
+ const parseQuery = (search) => {
25
+ if (!search) return {};
26
+ const params = new URLSearchParams(search);
27
+ const query = {};
28
+ for (const [key, value] of params) {
29
+ query[key] = value;
30
+ }
31
+ return query;
32
+ };
33
+
34
+ const RouteWrapper = ({ componentPath }) => {
35
+ const routeHistory = useHistory();
36
+ const routeLocation = useLocation();
37
+ const Component = loadComponent(componentPath);
38
+ return (
39
+ <Component
40
+ history={routeHistory}
41
+ location={{ ...routeLocation, query: parseQuery(routeLocation.search) }}
42
+ />
43
+ );
44
+ };
45
+
24
46
  const App = () => {
25
47
  return (
26
48
  <Router history={history}>
@@ -37,10 +59,7 @@ const App = () => {
37
59
  key={route.path || i}
38
60
  path={route.path}
39
61
  exact={route.path !== '/404'}
40
- render={() => {
41
- const Component = loadComponent(route.component);
42
- return <Component />;
43
- }}
62
+ render={() => <RouteWrapper componentPath={route.component} />}
44
63
  />
45
64
  ),
46
65
  )}
@@ -1,9 +1,8 @@
1
- import React, { useState, useEffect } from 'react';
2
- import { Avatar, Dropdown, Menu, Space } from 'antd';
3
1
  import ProLayout from '@ant-design/pro-layout';
4
2
  import history from '@/umi';
5
3
  import menuRoutes from '../../routes/menu';
6
4
  import getIcon from '@/utils/getIcon';
5
+ import { useLocation } from 'react-router-dom';
7
6
 
8
7
  const menuDataRender = (menuList) => {
9
8
  return menuList.map((item) => {
@@ -18,18 +17,28 @@ const menuDataRender = (menuList) => {
18
17
 
19
18
  const BasicLayout = (props) => {
20
19
  const { children } = props;
21
- const [location, setLocation] = useState(history.location);
20
+ const location = useLocation();
22
21
 
23
- useEffect(() => {
24
- const unlisten = history.listen((location) => {
25
- setLocation(location);
26
- });
27
- return () => unlisten();
28
- }, []);
22
+ const isLayoutFalse = (routes, pathname) => {
23
+ for (const route of routes) {
24
+ if (pathname === route.path || pathname.startsWith(route.path + '/')) {
25
+ if (route.layout === false) return true;
26
+ }
27
+ if (route.routes) {
28
+ if (isLayoutFalse(route.routes, pathname)) return true;
29
+ }
30
+ }
31
+ return false;
32
+ };
33
+
34
+ if (isLayoutFalse(menuRoutes, location.pathname)) {
35
+ return <>{children}</>;
36
+ }
29
37
 
30
38
  return (
31
39
  <ProLayout
32
40
  title="管理平台"
41
+ // pure
33
42
  logo={false}
34
43
  layout="mix"
35
44
  fixSiderbar={false}
@@ -1,5 +1,7 @@
1
1
  import React, { useState } from 'react';
2
2
 
3
- export default function Home() {
3
+ export default function Home(props) {
4
+ console.log(props);
5
+ const { history, location } = props;
4
6
  return <div>home</div>;
5
7
  }
@@ -0,0 +1,5 @@
1
+ import React, { useState } from 'react';
2
+
3
+ export default function Login() {
4
+ return <div>login</div>;
5
+ }