@lxzy/code-snippet 0.0.11 → 0.0.12
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 +1 -1
- package/src/App.tsx +24 -5
- package/src/pages/home.tsx +3 -1
package/package.json
CHANGED
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
|
)}
|