Skip to content

Commit b1d0781

Browse files
committed
refactor: Remove unused rest route param
1 parent f4107e1 commit b1d0781

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

src/router.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ export function Router(props) {
156156

157157
let pathRoute, defaultRoute, matchProps;
158158
toChildArray(props.children).some((/** @type {VNode<any>} */ vnode) => {
159-
const matches = exec(path, vnode.props.path, (matchProps = { ...vnode.props, path, pathParams, searchParams, rest: '' }));
159+
const matches = exec(path, vnode.props.path, (matchProps = { ...vnode.props, path, pathParams, searchParams }));
160160
if (matches) return (pathRoute = cloneElement(vnode, matchProps));
161161
if (vnode.props.default) defaultRoute = cloneElement(vnode, matchProps);
162162
});

test/router.test.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ describe('Router', () => {
115115
);
116116

117117
expect(scratch).to.have.property('textContent', 'Home');
118-
expect(Home).to.have.been.calledWith({ path: '/', searchParams: {}, pathParams: {}, rest: '', test: '2' });
118+
expect(Home).to.have.been.calledWith({ path: '/', searchParams: {}, pathParams: {}, test: '2' });
119119
expect(loc).to.deep.include({
120120
url: '/',
121121
path: '/',
@@ -144,7 +144,7 @@ describe('Router', () => {
144144
render(<App />, scratch);
145145

146146
expect(scratch).to.have.property('textContent', 'Home');
147-
expect(Home).to.have.been.calledWith({ path: '/', searchParams: {}, pathParams: {}, rest: '', test: '2' });
147+
expect(Home).to.have.been.calledWith({ path: '/', searchParams: {}, pathParams: {}, test: '2' });
148148
expect(loc).to.deep.include({
149149
url: '/',
150150
path: '/',
@@ -154,7 +154,7 @@ describe('Router', () => {
154154
set('3')
155155
await sleep(1);
156156

157-
expect(Home).to.have.been.calledWith({ path: '/', searchParams: {}, pathParams: {}, rest: '', test: '3' });
157+
expect(Home).to.have.been.calledWith({ path: '/', searchParams: {}, pathParams: {}, test: '3' });
158158
expect(loc).to.deep.include({
159159
url: '/',
160160
path: '/',
@@ -184,7 +184,7 @@ describe('Router', () => {
184184
);
185185

186186
expect(scratch).to.have.property('textContent', 'Home');
187-
expect(Home).to.have.been.calledWith({ path: '/', searchParams: {}, pathParams: {}, rest: '' });
187+
expect(Home).to.have.been.calledWith({ path: '/', searchParams: {}, pathParams: {} });
188188
expect(Profiles).not.to.have.been.called;
189189
expect(Profile).not.to.have.been.called;
190190
expect(Fallback).not.to.have.been.called;
@@ -200,7 +200,7 @@ describe('Router', () => {
200200

201201
expect(scratch).to.have.property('textContent', 'Profiles');
202202
expect(Home).not.to.have.been.called;
203-
expect(Profiles).to.have.been.calledWith({ path: '/profiles', searchParams: {}, pathParams: {}, rest: '' });
203+
expect(Profiles).to.have.been.calledWith({ path: '/profiles', searchParams: {}, pathParams: {} });
204204
expect(Profile).not.to.have.been.called;
205205
expect(Fallback).not.to.have.been.called;
206206

@@ -218,7 +218,7 @@ describe('Router', () => {
218218
expect(Home).not.to.have.been.called;
219219
expect(Profiles).not.to.have.been.called;
220220
expect(Profile).to.have.been.calledWith(
221-
{ path: '/profiles/bob', searchParams: {}, pathParams: { id: 'bob' }, id: 'bob', rest: '' },
221+
{ path: '/profiles/bob', searchParams: {}, pathParams: { id: 'bob' }, id: 'bob' },
222222
);
223223
expect(Fallback).not.to.have.been.called;
224224

@@ -237,7 +237,7 @@ describe('Router', () => {
237237
expect(Profiles).not.to.have.been.called;
238238
expect(Profile).not.to.have.been.called;
239239
expect(Fallback).to.have.been.calledWith(
240-
{ default: true, path: '/other', searchParams: { a: 'b', c: 'd' }, pathParams: {}, rest: '' },
240+
{ default: true, path: '/other', searchParams: { a: 'b', c: 'd' }, pathParams: {} },
241241
);
242242

243243
expect(loc).to.deep.include({
@@ -274,13 +274,13 @@ describe('Router', () => {
274274
);
275275

276276
expect(scratch).to.have.property('innerHTML', '');
277-
expect(A).to.have.been.calledWith({ path: '/', searchParams: {}, pathParams: {}, rest: '' });
277+
expect(A).to.have.been.calledWith({ path: '/', searchParams: {}, pathParams: {} });
278278

279279
A.resetHistory();
280280
await sleep(10);
281281

282282
expect(scratch).to.have.property('innerHTML', '<h1>A</h1><p>hello</p>');
283-
expect(A).to.have.been.calledWith({ path: '/', searchParams: {}, pathParams: {}, rest: '' });
283+
expect(A).to.have.been.calledWith({ path: '/', searchParams: {}, pathParams: {} });
284284

285285
A.resetHistory();
286286
loc.route('/b');
@@ -293,14 +293,14 @@ describe('Router', () => {
293293
expect(scratch).to.have.property('innerHTML', '<h1>A</h1><p>hello</p>');
294294
// We should never re-invoke <A /> while loading <B /> (that would be a remount of the old route):
295295
expect(A).not.to.have.been.called;
296-
expect(B).to.have.been.calledWith({ path: '/b', searchParams: {}, pathParams: {}, rest: '' });
296+
expect(B).to.have.been.calledWith({ path: '/b', searchParams: {}, pathParams: {} });
297297

298298
B.resetHistory();
299299
await sleep(10);
300300

301301
expect(scratch).to.have.property('innerHTML', '<h1>B</h1><p>hello</p>');
302302
expect(B).to.have.been.calledOnce;
303-
expect(B).to.have.been.calledWith({ path: '/b', searchParams: {}, pathParams: {}, rest: '' });
303+
expect(B).to.have.been.calledWith({ path: '/b', searchParams: {}, pathParams: {} });
304304

305305
B.resetHistory();
306306
loc.route('/c');
@@ -319,14 +319,14 @@ describe('Router', () => {
319319
expect(scratch).to.have.property('innerHTML', '<h1>B</h1><p>hello</p>');
320320
// We should never re-invoke <B /> while loading <C /> (that would be a remount of the old route):
321321
expect(B).not.to.have.been.called;
322-
expect(C).to.have.been.calledWith({ path: '/c', searchParams: {}, pathParams: {}, rest: '' });
322+
expect(C).to.have.been.calledWith({ path: '/c', searchParams: {}, pathParams: {} });
323323

324324
C.resetHistory();
325325
await sleep(10);
326326

327327
expect(scratch).to.have.property('innerHTML', '<h1>C</h1>');
328328
expect(C).to.have.been.calledOnce;
329-
expect(C).to.have.been.calledWith({ path: '/c', searchParams: {}, pathParams: {}, rest: '' });
329+
expect(C).to.have.been.calledWith({ path: '/c', searchParams: {}, pathParams: {} });
330330

331331
// "instant" routing to already-loaded routes
332332

@@ -338,7 +338,7 @@ describe('Router', () => {
338338
expect(scratch).to.have.property('innerHTML', '<h1>B</h1><p>hello</p>');
339339
expect(C).not.to.have.been.called;
340340
expect(B).to.have.been.calledOnce;
341-
expect(B).to.have.been.calledWith({ path: '/b', searchParams: {}, pathParams: {}, rest: '' });
341+
expect(B).to.have.been.calledWith({ path: '/b', searchParams: {}, pathParams: {} });
342342

343343
A.resetHistory();
344344
B.resetHistory();
@@ -348,7 +348,7 @@ describe('Router', () => {
348348
expect(scratch).to.have.property('innerHTML', '<h1>A</h1><p>hello</p>');
349349
expect(B).not.to.have.been.called;
350350
expect(A).to.have.been.calledOnce;
351-
expect(A).to.have.been.calledWith({ path: '/', searchParams: {}, pathParams: {}, rest: '' });
351+
expect(A).to.have.been.calledWith({ path: '/', searchParams: {}, pathParams: {} });
352352
});
353353

354354
it('rerenders same-component routes rather than swap', async () => {
@@ -437,7 +437,7 @@ describe('Router', () => {
437437
);
438438

439439
expect(scratch).to.have.property('innerHTML', '');
440-
expect(A).to.have.been.calledWith({ path: '/', searchParams: {}, pathParams: {}, rest: '' });
440+
expect(A).to.have.been.calledWith({ path: '/', searchParams: {}, pathParams: {} });
441441
expect(loadStart).to.have.been.calledWith('/');
442442
expect(loadEnd).not.to.have.been.called;
443443
expect(routeChange).not.to.have.been.called;
@@ -449,7 +449,7 @@ describe('Router', () => {
449449
await sleep(1);
450450

451451
expect(scratch).to.have.property('innerHTML', '<h1>A</h1><p>hello</p>');
452-
expect(A).to.have.been.calledWith({ path: '/', searchParams: {}, pathParams: {}, rest: '' });
452+
expect(A).to.have.been.calledWith({ path: '/', searchParams: {}, pathParams: {} });
453453
expect(loadStart).not.to.have.been.called;
454454
expect(loadEnd).to.have.been.calledWith('/');
455455
expect(routeChange).not.to.have.been.called;
@@ -1044,7 +1044,7 @@ describe('hydration', () => {
10441044
mutationObserver.observe(scratch, { childList: true, subtree: true });
10451045

10461046
expect(scratch).to.have.property('innerHTML', '<div><h1>A</h1><p>hello</p></div>');
1047-
expect(A).to.have.been.calledWith({ path: '/', searchParams: {}, pathParams: {}, rest: '' });
1047+
expect(A).to.have.been.calledWith({ path: '/', searchParams: {}, pathParams: {} });
10481048
const oldOptionsVnode = options.__b;
10491049
let hasMatched = false;
10501050
options.__b = (vnode) => {
@@ -1068,7 +1068,7 @@ describe('hydration', () => {
10681068
await sleep(10);
10691069

10701070
expect(scratch).to.have.property('innerHTML', '<div><h1>A</h1><p>hello</p></div>');
1071-
expect(A).to.have.been.calledWith({ path: '/', searchParams: {}, pathParams: {}, rest: '' });
1071+
expect(A).to.have.been.calledWith({ path: '/', searchParams: {}, pathParams: {} });
10721072
expect(mutations).to.have.length(0);
10731073

10741074
options.__b = oldOptionsVnode;

0 commit comments

Comments
 (0)