svelte-navigator-lite 1.1.2 → 1.1.3
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/router.svelte.d.ts +0 -1
- package/dist/router.svelte.js +4 -12
- package/dist/router.test.js +14 -23
- package/package.json +1 -1
package/dist/router.svelte.d.ts
CHANGED
package/dist/router.svelte.js
CHANGED
|
@@ -78,17 +78,7 @@ export function _createRouter(routeList = {}) {
|
|
|
78
78
|
if (match && route.searchParams) {
|
|
79
79
|
for (const key of route.searchParams) {
|
|
80
80
|
const val = searchParams.get(key);
|
|
81
|
-
if (val
|
|
82
|
-
match = false;
|
|
83
|
-
break;
|
|
84
|
-
}
|
|
85
|
-
params[key] = val;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
if (match && route.optionalSearchParams) {
|
|
89
|
-
for (const key of route.optionalSearchParams) {
|
|
90
|
-
const val = searchParams.get(key);
|
|
91
|
-
if (val !== null)
|
|
81
|
+
if (val)
|
|
92
82
|
params[key] = val;
|
|
93
83
|
}
|
|
94
84
|
}
|
|
@@ -150,7 +140,9 @@ export function _createRouter(routeList = {}) {
|
|
|
150
140
|
searchParams.set(param, params[param]);
|
|
151
141
|
}
|
|
152
142
|
}
|
|
153
|
-
|
|
143
|
+
const qs = searchParams.toString();
|
|
144
|
+
if (qs)
|
|
145
|
+
path += `?${qs}`;
|
|
154
146
|
}
|
|
155
147
|
await goto(path);
|
|
156
148
|
},
|
package/dist/router.test.js
CHANGED
|
@@ -138,38 +138,29 @@ describe('parseUrl — required searchParams', () => {
|
|
|
138
138
|
},
|
|
139
139
|
fallback: { rootPath: 'fallback', segments: [] },
|
|
140
140
|
};
|
|
141
|
-
it('
|
|
141
|
+
it('captures a search param when present', () => {
|
|
142
142
|
const r = makeRouter(routes, 'fallback');
|
|
143
143
|
r.parseUrl('http://localhost/password-reset?token=abc123');
|
|
144
144
|
expect(r.route).toBe('password-reset');
|
|
145
145
|
expect(r.params).toEqual({ token: 'abc123' });
|
|
146
146
|
});
|
|
147
|
-
it('
|
|
147
|
+
it('still matches when a search param is absent', () => {
|
|
148
148
|
const r = makeRouter(routes, 'fallback');
|
|
149
149
|
r.parseUrl('http://localhost/password-reset');
|
|
150
|
-
expect(r.
|
|
151
|
-
});
|
|
152
|
-
});
|
|
153
|
-
describe('parseUrl — optional searchParams', () => {
|
|
154
|
-
const routes = {
|
|
155
|
-
signup: {
|
|
156
|
-
rootPath: 'signup',
|
|
157
|
-
segments: [],
|
|
158
|
-
optionalSearchParams: ['redirect'],
|
|
159
|
-
},
|
|
160
|
-
};
|
|
161
|
-
it('captures optional search param when present', () => {
|
|
162
|
-
const r = makeRouter(routes, 'signup');
|
|
163
|
-
r.parseUrl('http://localhost/signup?redirect=%2Fdashboard');
|
|
164
|
-
expect(r.route).toBe('signup');
|
|
165
|
-
expect(r.params).toEqual({ redirect: '/dashboard' });
|
|
166
|
-
});
|
|
167
|
-
it('still matches when optional search param is absent', () => {
|
|
168
|
-
const r = makeRouter(routes, 'signup');
|
|
169
|
-
r.parseUrl('http://localhost/signup');
|
|
170
|
-
expect(r.route).toBe('signup');
|
|
150
|
+
expect(r.route).toBe('password-reset');
|
|
171
151
|
expect(r.params).toEqual({});
|
|
172
152
|
});
|
|
153
|
+
it('captures multiple search params independently', () => {
|
|
154
|
+
const r = makeRouter({
|
|
155
|
+
page: {
|
|
156
|
+
rootPath: 'items',
|
|
157
|
+
segments: [],
|
|
158
|
+
searchParams: ['page', 'sort'],
|
|
159
|
+
},
|
|
160
|
+
}, 'page');
|
|
161
|
+
r.parseUrl('http://localhost/items?page=2');
|
|
162
|
+
expect(r.params).toEqual({ page: '2' });
|
|
163
|
+
});
|
|
173
164
|
});
|
|
174
165
|
describe('parseUrl — fallback and notFound', () => {
|
|
175
166
|
it('falls back to defaultRoute and sets notFound=true on no match', () => {
|