solid-navigator 0.3.13 → 0.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.
- package/dist/dev.js +33 -21
- package/dist/dev.jsx +19 -15
- package/dist/index.js +33 -21
- package/dist/index.jsx +19 -15
- package/package.json +12 -11
package/dist/dev.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { createContext, children, createMemo, createSignal, onCleanup, batch, mergeProps, splitProps, createEffect, on
|
|
2
|
-
import { delegateEvents, createComponent, spread, mergeProps as mergeProps$1
|
|
1
|
+
import { createContext, children, createMemo, createSignal, onCleanup, useContext, batch, mergeProps, splitProps, createEffect, on } from 'solid-js';
|
|
2
|
+
import { delegateEvents, createComponent, template, spread, mergeProps as mergeProps$1 } from 'solid-js/web';
|
|
3
3
|
import { createStore, reconcile } from 'solid-js/store';
|
|
4
4
|
|
|
5
5
|
// src/navigator.ts
|
|
@@ -12,20 +12,20 @@ function createMatcher(path, partial, matchFilters) {
|
|
|
12
12
|
return (location2) => {
|
|
13
13
|
const locSegments = location2.split("/").filter(Boolean);
|
|
14
14
|
const lenDiff = locSegments.length - len;
|
|
15
|
-
if (lenDiff < 0 || lenDiff > 0 && splat === void 0 &&
|
|
15
|
+
if (lenDiff < 0 || lenDiff > 0 && splat === void 0 && true) {
|
|
16
16
|
return null;
|
|
17
17
|
}
|
|
18
18
|
const match = {
|
|
19
19
|
path: len ? "" : "/",
|
|
20
20
|
params: {}
|
|
21
21
|
};
|
|
22
|
-
const matchFilter = (s) =>
|
|
22
|
+
const matchFilter = (s) => void 0 ;
|
|
23
23
|
for (let i = 0; i < len; i++) {
|
|
24
24
|
const segment = segments[i];
|
|
25
25
|
const locSegment = locSegments[i];
|
|
26
26
|
const dynamic = segment[0] === ":";
|
|
27
27
|
const key = dynamic ? segment.slice(1) : segment;
|
|
28
|
-
if (dynamic && matchSegment(locSegment, matchFilter(
|
|
28
|
+
if (dynamic && matchSegment(locSegment, matchFilter())) {
|
|
29
29
|
match.params[key] = locSegment;
|
|
30
30
|
} else if (dynamic || !matchSegment(locSegment, segment)) {
|
|
31
31
|
return null;
|
|
@@ -34,7 +34,7 @@ function createMatcher(path, partial, matchFilters) {
|
|
|
34
34
|
}
|
|
35
35
|
if (splat) {
|
|
36
36
|
const remainder = lenDiff ? locSegments.slice(-lenDiff).join("/") : "";
|
|
37
|
-
if (matchSegment(remainder, matchFilter(
|
|
37
|
+
if (matchSegment(remainder, matchFilter())) {
|
|
38
38
|
match.params[splat] = remainder;
|
|
39
39
|
} else {
|
|
40
40
|
return null;
|
|
@@ -99,7 +99,7 @@ var isValidPath = (routes, pathname) => {
|
|
|
99
99
|
return matcher(pathname);
|
|
100
100
|
});
|
|
101
101
|
};
|
|
102
|
-
var
|
|
102
|
+
var getSearchAndHash = () => location.search + location.hash;
|
|
103
103
|
function expandOptionals(pattern) {
|
|
104
104
|
let match = /(\/?\:[^\/]+)\?/.exec(pattern);
|
|
105
105
|
if (!match)
|
|
@@ -126,11 +126,11 @@ function Router(props) {
|
|
|
126
126
|
const childRoutes = children(() => props.children).toArray;
|
|
127
127
|
const routes = createMemo(() => expandOptionalRoutes(flattenedRoutes(childRoutes())));
|
|
128
128
|
const [pathname, setPathname] = createSignal(location.pathname);
|
|
129
|
-
const [
|
|
129
|
+
const [searchAndHash, setSearchAndHash] = createSignal(getSearchAndHash());
|
|
130
130
|
const [params, setParams] = createStore({});
|
|
131
131
|
const [query, setQuery] = createStore({});
|
|
132
|
-
const
|
|
133
|
-
const loc = createLocation(
|
|
132
|
+
const pathnameWithSearchAndHash = createMemo(() => pathname() + searchAndHash());
|
|
133
|
+
const loc = createLocation(pathnameWithSearchAndHash, query, setQuery);
|
|
134
134
|
const matched = createMemo(() => {
|
|
135
135
|
if (!routes())
|
|
136
136
|
return;
|
|
@@ -154,11 +154,11 @@ function Router(props) {
|
|
|
154
154
|
route: matchedRoute
|
|
155
155
|
};
|
|
156
156
|
});
|
|
157
|
-
const navigate = createNavigate(routes, pathname, setPathname,
|
|
157
|
+
const navigate = createNavigate(routes, pathname, setPathname, setSearchAndHash);
|
|
158
158
|
const onPopState = (_event) => {
|
|
159
159
|
batch(() => {
|
|
160
160
|
setPathname(location.pathname);
|
|
161
|
-
|
|
161
|
+
setSearchAndHash(getSearchAndHash());
|
|
162
162
|
});
|
|
163
163
|
};
|
|
164
164
|
const onClick = (event) => {
|
|
@@ -192,7 +192,7 @@ function Router(props) {
|
|
|
192
192
|
navigate,
|
|
193
193
|
params,
|
|
194
194
|
location: loc,
|
|
195
|
-
|
|
195
|
+
setSearchAndHash,
|
|
196
196
|
setPathname,
|
|
197
197
|
setQuery,
|
|
198
198
|
query
|
|
@@ -219,7 +219,9 @@ var flattenedRoutes = (routes) => {
|
|
|
219
219
|
};
|
|
220
220
|
var flattenedRoute = (route) => {
|
|
221
221
|
const routes = [];
|
|
222
|
-
|
|
222
|
+
let components = {
|
|
223
|
+
...route.components || {}
|
|
224
|
+
};
|
|
223
225
|
let lastComponent = void 0;
|
|
224
226
|
if (route.component) {
|
|
225
227
|
lastComponent = route.component;
|
|
@@ -229,7 +231,9 @@ var flattenedRoute = (route) => {
|
|
|
229
231
|
components: {
|
|
230
232
|
...components
|
|
231
233
|
},
|
|
232
|
-
mergedComponents:
|
|
234
|
+
mergedComponents: {
|
|
235
|
+
...components
|
|
236
|
+
},
|
|
233
237
|
component: route.component || lastComponent
|
|
234
238
|
});
|
|
235
239
|
if (!route.children)
|
|
@@ -238,8 +242,11 @@ var flattenedRoute = (route) => {
|
|
|
238
242
|
const child = route.children[i];
|
|
239
243
|
if (!child)
|
|
240
244
|
continue;
|
|
245
|
+
let childComponents = {
|
|
246
|
+
...components
|
|
247
|
+
};
|
|
241
248
|
if (child.components) {
|
|
242
|
-
Object.assign(
|
|
249
|
+
Object.assign(childComponents, child.components);
|
|
243
250
|
}
|
|
244
251
|
if (child.component) {
|
|
245
252
|
lastComponent = child.component;
|
|
@@ -248,16 +255,21 @@ var flattenedRoute = (route) => {
|
|
|
248
255
|
if (!child.component) {
|
|
249
256
|
throw new Error("Route: No component for " + child.path);
|
|
250
257
|
}
|
|
251
|
-
|
|
258
|
+
childComponents[child.path] = child.component;
|
|
259
|
+
components = {
|
|
260
|
+
...childComponents
|
|
261
|
+
};
|
|
252
262
|
continue;
|
|
253
263
|
}
|
|
254
264
|
routes.push(...flattenedRoute({
|
|
255
265
|
...child,
|
|
256
266
|
path: route.path + child.path,
|
|
257
267
|
components: {
|
|
258
|
-
...
|
|
268
|
+
...childComponents
|
|
269
|
+
},
|
|
270
|
+
mergedComponents: {
|
|
271
|
+
...childComponents
|
|
259
272
|
},
|
|
260
|
-
mergedComponents: components,
|
|
261
273
|
component: child.component || lastComponent
|
|
262
274
|
}));
|
|
263
275
|
}
|
|
@@ -275,7 +287,7 @@ var expandOptionalRoutes = (routes) => {
|
|
|
275
287
|
});
|
|
276
288
|
return newRoutes;
|
|
277
289
|
};
|
|
278
|
-
var createNavigate = (routes, pathname, setPathname,
|
|
290
|
+
var createNavigate = (routes, pathname, setPathname, setSearchAndHash) => {
|
|
279
291
|
return (path, options) => {
|
|
280
292
|
let newPath = path;
|
|
281
293
|
let currentPathname = pathname();
|
|
@@ -298,7 +310,7 @@ var createNavigate = (routes, pathname, setPathname, setHashAndSearch) => {
|
|
|
298
310
|
}
|
|
299
311
|
batch(() => {
|
|
300
312
|
setPathname(location.pathname);
|
|
301
|
-
|
|
313
|
+
setSearchAndHash(getSearchAndHash());
|
|
302
314
|
});
|
|
303
315
|
};
|
|
304
316
|
};
|
package/dist/dev.jsx
CHANGED
|
@@ -113,7 +113,7 @@ var isValidPath = (routes, pathname) => {
|
|
|
113
113
|
return matcher(pathname);
|
|
114
114
|
});
|
|
115
115
|
};
|
|
116
|
-
var
|
|
116
|
+
var getSearchAndHash = () => location.search + location.hash;
|
|
117
117
|
function expandOptionals(pattern) {
|
|
118
118
|
let match = /(\/?\:[^\/]+)\?/.exec(pattern);
|
|
119
119
|
if (!match)
|
|
@@ -140,11 +140,11 @@ function Router(props) {
|
|
|
140
140
|
const childRoutes = children(() => props.children).toArray;
|
|
141
141
|
const routes = createMemo2(() => expandOptionalRoutes(flattenedRoutes(childRoutes())));
|
|
142
142
|
const [pathname, setPathname] = createSignal(location.pathname);
|
|
143
|
-
const [
|
|
143
|
+
const [searchAndHash, setSearchAndHash] = createSignal(getSearchAndHash());
|
|
144
144
|
const [params, setParams] = createStore2({});
|
|
145
145
|
const [query, setQuery] = createStore2({});
|
|
146
|
-
const
|
|
147
|
-
const loc = createLocation(
|
|
146
|
+
const pathnameWithSearchAndHash = createMemo2(() => pathname() + searchAndHash());
|
|
147
|
+
const loc = createLocation(pathnameWithSearchAndHash, query, setQuery);
|
|
148
148
|
const matched = createMemo2(() => {
|
|
149
149
|
if (!routes())
|
|
150
150
|
return;
|
|
@@ -165,11 +165,11 @@ function Router(props) {
|
|
|
165
165
|
}
|
|
166
166
|
return { match: pathMatch, route: matchedRoute };
|
|
167
167
|
});
|
|
168
|
-
const navigate = createNavigate(routes, pathname, setPathname,
|
|
168
|
+
const navigate = createNavigate(routes, pathname, setPathname, setSearchAndHash);
|
|
169
169
|
const onPopState = (_event) => {
|
|
170
170
|
batch(() => {
|
|
171
171
|
setPathname(location.pathname);
|
|
172
|
-
|
|
172
|
+
setSearchAndHash(getSearchAndHash());
|
|
173
173
|
});
|
|
174
174
|
};
|
|
175
175
|
const onClick = (event) => {
|
|
@@ -203,7 +203,7 @@ function Router(props) {
|
|
|
203
203
|
navigate,
|
|
204
204
|
params,
|
|
205
205
|
location: loc,
|
|
206
|
-
|
|
206
|
+
setSearchAndHash,
|
|
207
207
|
setPathname,
|
|
208
208
|
setQuery,
|
|
209
209
|
query
|
|
@@ -227,7 +227,9 @@ var flattenedRoutes = (routes) => {
|
|
|
227
227
|
};
|
|
228
228
|
var flattenedRoute = (route) => {
|
|
229
229
|
const routes = [];
|
|
230
|
-
|
|
230
|
+
let components = {
|
|
231
|
+
...route.components || {}
|
|
232
|
+
};
|
|
231
233
|
let lastComponent = void 0;
|
|
232
234
|
if (route.component) {
|
|
233
235
|
lastComponent = route.component;
|
|
@@ -235,7 +237,7 @@ var flattenedRoute = (route) => {
|
|
|
235
237
|
routes.push({
|
|
236
238
|
...route,
|
|
237
239
|
components: { ...components },
|
|
238
|
-
mergedComponents: components,
|
|
240
|
+
mergedComponents: { ...components },
|
|
239
241
|
component: route.component || lastComponent
|
|
240
242
|
});
|
|
241
243
|
if (!route.children)
|
|
@@ -244,8 +246,9 @@ var flattenedRoute = (route) => {
|
|
|
244
246
|
const child = route.children[i];
|
|
245
247
|
if (!child)
|
|
246
248
|
continue;
|
|
249
|
+
let childComponents = { ...components };
|
|
247
250
|
if (child.components) {
|
|
248
|
-
Object.assign(
|
|
251
|
+
Object.assign(childComponents, child.components);
|
|
249
252
|
}
|
|
250
253
|
if (child.component) {
|
|
251
254
|
lastComponent = child.component;
|
|
@@ -254,15 +257,16 @@ var flattenedRoute = (route) => {
|
|
|
254
257
|
if (!child.component) {
|
|
255
258
|
throw new Error("Route: No component for " + child.path);
|
|
256
259
|
}
|
|
257
|
-
|
|
260
|
+
childComponents[child.path] = child.component;
|
|
261
|
+
components = { ...childComponents };
|
|
258
262
|
continue;
|
|
259
263
|
}
|
|
260
264
|
routes.push(
|
|
261
265
|
...flattenedRoute({
|
|
262
266
|
...child,
|
|
263
267
|
path: route.path + child.path,
|
|
264
|
-
components: { ...
|
|
265
|
-
mergedComponents:
|
|
268
|
+
components: { ...childComponents },
|
|
269
|
+
mergedComponents: { ...childComponents },
|
|
266
270
|
component: child.component || lastComponent
|
|
267
271
|
})
|
|
268
272
|
);
|
|
@@ -281,7 +285,7 @@ var expandOptionalRoutes = (routes) => {
|
|
|
281
285
|
|
|
282
286
|
// src/navigator.ts
|
|
283
287
|
import { reconcile as reconcile3 } from "solid-js/store";
|
|
284
|
-
var createNavigate = (routes, pathname, setPathname,
|
|
288
|
+
var createNavigate = (routes, pathname, setPathname, setSearchAndHash) => {
|
|
285
289
|
return (path, options) => {
|
|
286
290
|
let newPath = path;
|
|
287
291
|
let currentPathname = pathname();
|
|
@@ -304,7 +308,7 @@ var createNavigate = (routes, pathname, setPathname, setHashAndSearch) => {
|
|
|
304
308
|
}
|
|
305
309
|
batch2(() => {
|
|
306
310
|
setPathname(location.pathname);
|
|
307
|
-
|
|
311
|
+
setSearchAndHash(getSearchAndHash());
|
|
308
312
|
});
|
|
309
313
|
};
|
|
310
314
|
};
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { createContext, children, createMemo, createSignal, onCleanup, batch, mergeProps, splitProps, createEffect, on
|
|
2
|
-
import { delegateEvents, createComponent, spread, mergeProps as mergeProps$1
|
|
1
|
+
import { createContext, children, createMemo, createSignal, onCleanup, useContext, batch, mergeProps, splitProps, createEffect, on } from 'solid-js';
|
|
2
|
+
import { delegateEvents, createComponent, template, spread, mergeProps as mergeProps$1 } from 'solid-js/web';
|
|
3
3
|
import { createStore, reconcile } from 'solid-js/store';
|
|
4
4
|
|
|
5
5
|
// src/navigator.ts
|
|
@@ -12,20 +12,20 @@ function createMatcher(path, partial, matchFilters) {
|
|
|
12
12
|
return (location2) => {
|
|
13
13
|
const locSegments = location2.split("/").filter(Boolean);
|
|
14
14
|
const lenDiff = locSegments.length - len;
|
|
15
|
-
if (lenDiff < 0 || lenDiff > 0 && splat === void 0 &&
|
|
15
|
+
if (lenDiff < 0 || lenDiff > 0 && splat === void 0 && true) {
|
|
16
16
|
return null;
|
|
17
17
|
}
|
|
18
18
|
const match = {
|
|
19
19
|
path: len ? "" : "/",
|
|
20
20
|
params: {}
|
|
21
21
|
};
|
|
22
|
-
const matchFilter = (s) =>
|
|
22
|
+
const matchFilter = (s) => void 0 ;
|
|
23
23
|
for (let i = 0; i < len; i++) {
|
|
24
24
|
const segment = segments[i];
|
|
25
25
|
const locSegment = locSegments[i];
|
|
26
26
|
const dynamic = segment[0] === ":";
|
|
27
27
|
const key = dynamic ? segment.slice(1) : segment;
|
|
28
|
-
if (dynamic && matchSegment(locSegment, matchFilter(
|
|
28
|
+
if (dynamic && matchSegment(locSegment, matchFilter())) {
|
|
29
29
|
match.params[key] = locSegment;
|
|
30
30
|
} else if (dynamic || !matchSegment(locSegment, segment)) {
|
|
31
31
|
return null;
|
|
@@ -34,7 +34,7 @@ function createMatcher(path, partial, matchFilters) {
|
|
|
34
34
|
}
|
|
35
35
|
if (splat) {
|
|
36
36
|
const remainder = lenDiff ? locSegments.slice(-lenDiff).join("/") : "";
|
|
37
|
-
if (matchSegment(remainder, matchFilter(
|
|
37
|
+
if (matchSegment(remainder, matchFilter())) {
|
|
38
38
|
match.params[splat] = remainder;
|
|
39
39
|
} else {
|
|
40
40
|
return null;
|
|
@@ -99,7 +99,7 @@ var isValidPath = (routes, pathname) => {
|
|
|
99
99
|
return matcher(pathname);
|
|
100
100
|
});
|
|
101
101
|
};
|
|
102
|
-
var
|
|
102
|
+
var getSearchAndHash = () => location.search + location.hash;
|
|
103
103
|
function expandOptionals(pattern) {
|
|
104
104
|
let match = /(\/?\:[^\/]+)\?/.exec(pattern);
|
|
105
105
|
if (!match)
|
|
@@ -126,11 +126,11 @@ function Router(props) {
|
|
|
126
126
|
const childRoutes = children(() => props.children).toArray;
|
|
127
127
|
const routes = createMemo(() => expandOptionalRoutes(flattenedRoutes(childRoutes())));
|
|
128
128
|
const [pathname, setPathname] = createSignal(location.pathname);
|
|
129
|
-
const [
|
|
129
|
+
const [searchAndHash, setSearchAndHash] = createSignal(getSearchAndHash());
|
|
130
130
|
const [params, setParams] = createStore({});
|
|
131
131
|
const [query, setQuery] = createStore({});
|
|
132
|
-
const
|
|
133
|
-
const loc = createLocation(
|
|
132
|
+
const pathnameWithSearchAndHash = createMemo(() => pathname() + searchAndHash());
|
|
133
|
+
const loc = createLocation(pathnameWithSearchAndHash, query, setQuery);
|
|
134
134
|
const matched = createMemo(() => {
|
|
135
135
|
if (!routes())
|
|
136
136
|
return;
|
|
@@ -154,11 +154,11 @@ function Router(props) {
|
|
|
154
154
|
route: matchedRoute
|
|
155
155
|
};
|
|
156
156
|
});
|
|
157
|
-
const navigate = createNavigate(routes, pathname, setPathname,
|
|
157
|
+
const navigate = createNavigate(routes, pathname, setPathname, setSearchAndHash);
|
|
158
158
|
const onPopState = (_event) => {
|
|
159
159
|
batch(() => {
|
|
160
160
|
setPathname(location.pathname);
|
|
161
|
-
|
|
161
|
+
setSearchAndHash(getSearchAndHash());
|
|
162
162
|
});
|
|
163
163
|
};
|
|
164
164
|
const onClick = (event) => {
|
|
@@ -192,7 +192,7 @@ function Router(props) {
|
|
|
192
192
|
navigate,
|
|
193
193
|
params,
|
|
194
194
|
location: loc,
|
|
195
|
-
|
|
195
|
+
setSearchAndHash,
|
|
196
196
|
setPathname,
|
|
197
197
|
setQuery,
|
|
198
198
|
query
|
|
@@ -219,7 +219,9 @@ var flattenedRoutes = (routes) => {
|
|
|
219
219
|
};
|
|
220
220
|
var flattenedRoute = (route) => {
|
|
221
221
|
const routes = [];
|
|
222
|
-
|
|
222
|
+
let components = {
|
|
223
|
+
...route.components || {}
|
|
224
|
+
};
|
|
223
225
|
let lastComponent = void 0;
|
|
224
226
|
if (route.component) {
|
|
225
227
|
lastComponent = route.component;
|
|
@@ -229,7 +231,9 @@ var flattenedRoute = (route) => {
|
|
|
229
231
|
components: {
|
|
230
232
|
...components
|
|
231
233
|
},
|
|
232
|
-
mergedComponents:
|
|
234
|
+
mergedComponents: {
|
|
235
|
+
...components
|
|
236
|
+
},
|
|
233
237
|
component: route.component || lastComponent
|
|
234
238
|
});
|
|
235
239
|
if (!route.children)
|
|
@@ -238,8 +242,11 @@ var flattenedRoute = (route) => {
|
|
|
238
242
|
const child = route.children[i];
|
|
239
243
|
if (!child)
|
|
240
244
|
continue;
|
|
245
|
+
let childComponents = {
|
|
246
|
+
...components
|
|
247
|
+
};
|
|
241
248
|
if (child.components) {
|
|
242
|
-
Object.assign(
|
|
249
|
+
Object.assign(childComponents, child.components);
|
|
243
250
|
}
|
|
244
251
|
if (child.component) {
|
|
245
252
|
lastComponent = child.component;
|
|
@@ -248,16 +255,21 @@ var flattenedRoute = (route) => {
|
|
|
248
255
|
if (!child.component) {
|
|
249
256
|
throw new Error("Route: No component for " + child.path);
|
|
250
257
|
}
|
|
251
|
-
|
|
258
|
+
childComponents[child.path] = child.component;
|
|
259
|
+
components = {
|
|
260
|
+
...childComponents
|
|
261
|
+
};
|
|
252
262
|
continue;
|
|
253
263
|
}
|
|
254
264
|
routes.push(...flattenedRoute({
|
|
255
265
|
...child,
|
|
256
266
|
path: route.path + child.path,
|
|
257
267
|
components: {
|
|
258
|
-
...
|
|
268
|
+
...childComponents
|
|
269
|
+
},
|
|
270
|
+
mergedComponents: {
|
|
271
|
+
...childComponents
|
|
259
272
|
},
|
|
260
|
-
mergedComponents: components,
|
|
261
273
|
component: child.component || lastComponent
|
|
262
274
|
}));
|
|
263
275
|
}
|
|
@@ -275,7 +287,7 @@ var expandOptionalRoutes = (routes) => {
|
|
|
275
287
|
});
|
|
276
288
|
return newRoutes;
|
|
277
289
|
};
|
|
278
|
-
var createNavigate = (routes, pathname, setPathname,
|
|
290
|
+
var createNavigate = (routes, pathname, setPathname, setSearchAndHash) => {
|
|
279
291
|
return (path, options) => {
|
|
280
292
|
let newPath = path;
|
|
281
293
|
let currentPathname = pathname();
|
|
@@ -296,7 +308,7 @@ var createNavigate = (routes, pathname, setPathname, setHashAndSearch) => {
|
|
|
296
308
|
if (!isValidPath(routes, location.pathname)) ;
|
|
297
309
|
batch(() => {
|
|
298
310
|
setPathname(location.pathname);
|
|
299
|
-
|
|
311
|
+
setSearchAndHash(getSearchAndHash());
|
|
300
312
|
});
|
|
301
313
|
};
|
|
302
314
|
};
|
package/dist/index.jsx
CHANGED
|
@@ -113,7 +113,7 @@ var isValidPath = (routes, pathname) => {
|
|
|
113
113
|
return matcher(pathname);
|
|
114
114
|
});
|
|
115
115
|
};
|
|
116
|
-
var
|
|
116
|
+
var getSearchAndHash = () => location.search + location.hash;
|
|
117
117
|
function expandOptionals(pattern) {
|
|
118
118
|
let match = /(\/?\:[^\/]+)\?/.exec(pattern);
|
|
119
119
|
if (!match)
|
|
@@ -140,11 +140,11 @@ function Router(props) {
|
|
|
140
140
|
const childRoutes = children(() => props.children).toArray;
|
|
141
141
|
const routes = createMemo2(() => expandOptionalRoutes(flattenedRoutes(childRoutes())));
|
|
142
142
|
const [pathname, setPathname] = createSignal(location.pathname);
|
|
143
|
-
const [
|
|
143
|
+
const [searchAndHash, setSearchAndHash] = createSignal(getSearchAndHash());
|
|
144
144
|
const [params, setParams] = createStore2({});
|
|
145
145
|
const [query, setQuery] = createStore2({});
|
|
146
|
-
const
|
|
147
|
-
const loc = createLocation(
|
|
146
|
+
const pathnameWithSearchAndHash = createMemo2(() => pathname() + searchAndHash());
|
|
147
|
+
const loc = createLocation(pathnameWithSearchAndHash, query, setQuery);
|
|
148
148
|
const matched = createMemo2(() => {
|
|
149
149
|
if (!routes())
|
|
150
150
|
return;
|
|
@@ -165,11 +165,11 @@ function Router(props) {
|
|
|
165
165
|
}
|
|
166
166
|
return { match: pathMatch, route: matchedRoute };
|
|
167
167
|
});
|
|
168
|
-
const navigate = createNavigate(routes, pathname, setPathname,
|
|
168
|
+
const navigate = createNavigate(routes, pathname, setPathname, setSearchAndHash);
|
|
169
169
|
const onPopState = (_event) => {
|
|
170
170
|
batch(() => {
|
|
171
171
|
setPathname(location.pathname);
|
|
172
|
-
|
|
172
|
+
setSearchAndHash(getSearchAndHash());
|
|
173
173
|
});
|
|
174
174
|
};
|
|
175
175
|
const onClick = (event) => {
|
|
@@ -203,7 +203,7 @@ function Router(props) {
|
|
|
203
203
|
navigate,
|
|
204
204
|
params,
|
|
205
205
|
location: loc,
|
|
206
|
-
|
|
206
|
+
setSearchAndHash,
|
|
207
207
|
setPathname,
|
|
208
208
|
setQuery,
|
|
209
209
|
query
|
|
@@ -227,7 +227,9 @@ var flattenedRoutes = (routes) => {
|
|
|
227
227
|
};
|
|
228
228
|
var flattenedRoute = (route) => {
|
|
229
229
|
const routes = [];
|
|
230
|
-
|
|
230
|
+
let components = {
|
|
231
|
+
...route.components || {}
|
|
232
|
+
};
|
|
231
233
|
let lastComponent = void 0;
|
|
232
234
|
if (route.component) {
|
|
233
235
|
lastComponent = route.component;
|
|
@@ -235,7 +237,7 @@ var flattenedRoute = (route) => {
|
|
|
235
237
|
routes.push({
|
|
236
238
|
...route,
|
|
237
239
|
components: { ...components },
|
|
238
|
-
mergedComponents: components,
|
|
240
|
+
mergedComponents: { ...components },
|
|
239
241
|
component: route.component || lastComponent
|
|
240
242
|
});
|
|
241
243
|
if (!route.children)
|
|
@@ -244,8 +246,9 @@ var flattenedRoute = (route) => {
|
|
|
244
246
|
const child = route.children[i];
|
|
245
247
|
if (!child)
|
|
246
248
|
continue;
|
|
249
|
+
let childComponents = { ...components };
|
|
247
250
|
if (child.components) {
|
|
248
|
-
Object.assign(
|
|
251
|
+
Object.assign(childComponents, child.components);
|
|
249
252
|
}
|
|
250
253
|
if (child.component) {
|
|
251
254
|
lastComponent = child.component;
|
|
@@ -254,15 +257,16 @@ var flattenedRoute = (route) => {
|
|
|
254
257
|
if (!child.component) {
|
|
255
258
|
throw new Error("Route: No component for " + child.path);
|
|
256
259
|
}
|
|
257
|
-
|
|
260
|
+
childComponents[child.path] = child.component;
|
|
261
|
+
components = { ...childComponents };
|
|
258
262
|
continue;
|
|
259
263
|
}
|
|
260
264
|
routes.push(
|
|
261
265
|
...flattenedRoute({
|
|
262
266
|
...child,
|
|
263
267
|
path: route.path + child.path,
|
|
264
|
-
components: { ...
|
|
265
|
-
mergedComponents:
|
|
268
|
+
components: { ...childComponents },
|
|
269
|
+
mergedComponents: { ...childComponents },
|
|
266
270
|
component: child.component || lastComponent
|
|
267
271
|
})
|
|
268
272
|
);
|
|
@@ -281,7 +285,7 @@ var expandOptionalRoutes = (routes) => {
|
|
|
281
285
|
|
|
282
286
|
// src/navigator.ts
|
|
283
287
|
import { reconcile as reconcile3 } from "solid-js/store";
|
|
284
|
-
var createNavigate = (routes, pathname, setPathname,
|
|
288
|
+
var createNavigate = (routes, pathname, setPathname, setSearchAndHash) => {
|
|
285
289
|
return (path, options) => {
|
|
286
290
|
let newPath = path;
|
|
287
291
|
let currentPathname = pathname();
|
|
@@ -303,7 +307,7 @@ var createNavigate = (routes, pathname, setPathname, setHashAndSearch) => {
|
|
|
303
307
|
}
|
|
304
308
|
batch2(() => {
|
|
305
309
|
setPathname(location.pathname);
|
|
306
|
-
|
|
310
|
+
setSearchAndHash(getSearchAndHash());
|
|
307
311
|
});
|
|
308
312
|
};
|
|
309
313
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "solid-navigator",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Solid Navigator is a library that is inspired by vue router and solid router.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "SupertigerDev",
|
|
@@ -40,6 +40,16 @@
|
|
|
40
40
|
}
|
|
41
41
|
},
|
|
42
42
|
"typesVersions": {},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"dev": "vite serve dev",
|
|
45
|
+
"build": "tsup",
|
|
46
|
+
"prepublishOnly": "pnpm build",
|
|
47
|
+
"format": "prettier --ignore-path .gitignore -w \"src/**/*.{js,ts,json,css,tsx,jsx}\" \"dev/**/*.{js,ts,json,css,tsx,jsx}\"",
|
|
48
|
+
"lint": "concurrently pnpm:lint:*",
|
|
49
|
+
"lint:code": "eslint --ignore-path .gitignore --max-warnings 0 src/**/*.{js,ts,tsx,jsx}",
|
|
50
|
+
"lint:types": "tsc --noEmit",
|
|
51
|
+
"update-deps": "pnpm up -Li"
|
|
52
|
+
},
|
|
43
53
|
"peerDependencies": {
|
|
44
54
|
"solid-js": "^1.6.0"
|
|
45
55
|
},
|
|
@@ -69,14 +79,5 @@
|
|
|
69
79
|
"engines": {
|
|
70
80
|
"node": ">=18",
|
|
71
81
|
"pnpm": ">=8.6.0"
|
|
72
|
-
},
|
|
73
|
-
"scripts": {
|
|
74
|
-
"dev": "vite serve dev",
|
|
75
|
-
"build": "tsup",
|
|
76
|
-
"format": "prettier --ignore-path .gitignore -w \"src/**/*.{js,ts,json,css,tsx,jsx}\" \"dev/**/*.{js,ts,json,css,tsx,jsx}\"",
|
|
77
|
-
"lint": "concurrently pnpm:lint:*",
|
|
78
|
-
"lint:code": "eslint --ignore-path .gitignore --max-warnings 0 src/**/*.{js,ts,tsx,jsx}",
|
|
79
|
-
"lint:types": "tsc --noEmit",
|
|
80
|
-
"update-deps": "pnpm up -Li"
|
|
81
82
|
}
|
|
82
|
-
}
|
|
83
|
+
}
|