@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lxzy/code-snippet",
3
- "version": "0.0.11",
3
+ "version": "0.0.12",
4
4
  "files": [
5
5
  "*",
6
6
  "!dist",
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,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
  }