@lemon-fe/mini-app 1.3.0 → 1.4.0

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.
@@ -20,6 +20,14 @@ interface Props {
20
20
  * @default true
21
21
  */
22
22
  capsule?: boolean;
23
+ /**
24
+ * @description 初始路由路径(不传则使用当前 URL 或 pages[0])
25
+ */
26
+ initialPath?: string;
27
+ /**
28
+ * @description 路由基础路径(类似 react-router 的 basename),用于从 URL 中裁剪前缀
29
+ */
30
+ routerBase?: string;
23
31
  }
24
32
  export default function AppContainer(props: Props): JSX.Element;
25
33
  export {};
@@ -54,12 +54,51 @@ export default function AppContainer(props) {
54
54
  children = props.children,
55
55
  headerStyle = props.headerStyle,
56
56
  _props$capsule = props.capsule,
57
- capsule = _props$capsule === void 0 ? true : _props$capsule;
57
+ capsule = _props$capsule === void 0 ? true : _props$capsule,
58
+ initialPath = props.initialPath,
59
+ routerBase = props.routerBase;
58
60
 
59
- var _useState = useState({
60
- routes: [{
61
- route: pages[0]
62
- }]
61
+ var _useState = useState(function () {
62
+ var path = initialPath;
63
+
64
+ if (!path && typeof window !== 'undefined') {
65
+ var _window$location = window.location,
66
+ pathname = _window$location.pathname,
67
+ search = _window$location.search;
68
+ var realPathname = pathname;
69
+
70
+ if (routerBase && pathname.indexOf(routerBase) === 0) {
71
+ realPathname = pathname.slice(routerBase.length) || '/';
72
+ }
73
+
74
+ path = "".concat(realPathname).concat(search);
75
+ }
76
+
77
+ if (path) {
78
+ var _parsePath = parsePath(path),
79
+ _pathname = _parsePath.pathname,
80
+ _search = _parsePath.search;
81
+
82
+ var params = _search ? Object.fromEntries(Array.from(new URLSearchParams(_search).entries())) : {};
83
+ var page = pages.find(function (item) {
84
+ return item.path === _pathname;
85
+ });
86
+
87
+ if (page !== undefined) {
88
+ return {
89
+ routes: [{
90
+ route: page,
91
+ params: params
92
+ }]
93
+ };
94
+ }
95
+ }
96
+
97
+ return {
98
+ routes: [{
99
+ route: pages[0]
100
+ }]
101
+ };
63
102
  }),
64
103
  _useState2 = _slicedToArray(_useState, 2),
65
104
  state = _useState2[0],
@@ -135,14 +174,14 @@ export default function AppContainer(props) {
135
174
  }, []);
136
175
  var navigate = useMemoizedFun( /*#__PURE__*/function () {
137
176
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(path, otherParams) {
138
- var routes, _parsePath, pathname, search, params, routeIndex, nextRoutes, page;
177
+ var routes, _parsePath2, pathname, search, params, routeIndex, nextRoutes, page;
139
178
 
140
179
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
141
180
  while (1) {
142
181
  switch (_context2.prev = _context2.next) {
143
182
  case 0:
144
183
  routes = state.routes;
145
- _parsePath = parsePath(path), pathname = _parsePath.pathname, search = _parsePath.search;
184
+ _parsePath2 = parsePath(path), pathname = _parsePath2.pathname, search = _parsePath2.search;
146
185
  params = search ? Object.fromEntries(Array.from(new URLSearchParams(search).entries())) : {};
147
186
  Object.assign(params, otherParams);
148
187
  routeIndex = routes.findIndex(function (item) {
@@ -193,14 +232,14 @@ export default function AppContainer(props) {
193
232
  }());
194
233
  var replace = useMemoizedFun( /*#__PURE__*/function () {
195
234
  var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(path, otherParams) {
196
- var routes, _parsePath2, pathname, search, params, routeIndex, nextRoutes, page, newRoute;
235
+ var routes, _parsePath3, pathname, search, params, routeIndex, nextRoutes, page, newRoute;
197
236
 
198
237
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
199
238
  while (1) {
200
239
  switch (_context3.prev = _context3.next) {
201
240
  case 0:
202
241
  routes = state.routes;
203
- _parsePath2 = parsePath(path), pathname = _parsePath2.pathname, search = _parsePath2.search;
242
+ _parsePath3 = parsePath(path), pathname = _parsePath3.pathname, search = _parsePath3.search;
204
243
  params = search ? Object.fromEntries(Array.from(new URLSearchParams(search).entries())) : {};
205
244
  Object.assign(params, otherParams);
206
245
  routeIndex = routes.findIndex(function (item) {
@@ -50,9 +50,8 @@
50
50
  }
51
51
 
52
52
  .lemon-route-header-center {
53
- font-weight: bold;
54
- /* prettier-ignore */
55
- font-size: 16PX;
53
+ font-weight: normal;
54
+ font-size: 18px;
56
55
  /* prettier-ignore */
57
56
  line-height: 44PX;
58
57
  text-align: center;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lemon-fe/mini-app",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "description": "> TODO: description",
5
5
  "author": "鲁盛杰 <lusj@cnlemon.net>",
6
6
  "homepage": "",
@@ -31,5 +31,5 @@
31
31
  "react": "^17.0.2",
32
32
  "react-dom": "17.0.2"
33
33
  },
34
- "gitHead": "d8e1da1a747ce526b80273636a3bcac9e9ce1ffe"
34
+ "gitHead": "fbde6ae2d79fe59624653cd88f15aebe3f21e270"
35
35
  }