Skip to content

Commit c113e3b

Browse files
committed
refactor: Remove unused rest route param
1 parent d60e833 commit c113e3b

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

src/router.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ export function Router(props) {
136136

137137
let pathRoute, defaultRoute, matchProps;
138138
toChildArray(props.children).some((/** @type {VNode<any>} */ vnode) => {
139-
const matches = exec(path, vnode.props.path, (matchProps = { ...vnode.props, path, pathParams, searchParams, rest: '' }));
139+
const matches = exec(path, vnode.props.path, (matchProps = { ...vnode.props, path, pathParams, searchParams }));
140140
if (matches) return (pathRoute = cloneElement(vnode, matchProps));
141141
if (vnode.props.default) defaultRoute = cloneElement(vnode, matchProps);
142142
});

test/router.test.js

+19-19
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ describe('Router', () => {
7474
);
7575

7676
expect(scratch).to.have.property('textContent', 'Home');
77-
expect(Home).to.have.been.calledWith({ path: '/', searchParams: {}, pathParams: {}, rest: '', test: '2' });
77+
expect(Home).to.have.been.calledWith({ path: '/', searchParams: {}, pathParams: {}, test: '2' });
7878
expect(loc).to.deep.include({
7979
url: '/',
8080
path: '/',
@@ -103,7 +103,7 @@ describe('Router', () => {
103103
render(<App />, scratch);
104104

105105
expect(scratch).to.have.property('textContent', 'Home');
106-
expect(Home).to.have.been.calledWith({ path: '/', searchParams: {}, pathParams: {}, rest: '', test: '2' });
106+
expect(Home).to.have.been.calledWith({ path: '/', searchParams: {}, pathParams: {}, test: '2' });
107107
expect(loc).to.deep.include({
108108
url: '/',
109109
path: '/',
@@ -113,7 +113,7 @@ describe('Router', () => {
113113
set('3')
114114
await sleep(1);
115115

116-
expect(Home).to.have.been.calledWith({ path: '/', searchParams: {}, pathParams: {}, rest: '', test: '3' });
116+
expect(Home).to.have.been.calledWith({ path: '/', searchParams: {}, pathParams: {}, test: '3' });
117117
expect(loc).to.deep.include({
118118
url: '/',
119119
path: '/',
@@ -143,7 +143,7 @@ describe('Router', () => {
143143
);
144144

145145
expect(scratch).to.have.property('textContent', 'Home');
146-
expect(Home).to.have.been.calledWith({ path: '/', searchParams: {}, pathParams: {}, rest: '' });
146+
expect(Home).to.have.been.calledWith({ path: '/', searchParams: {}, pathParams: {} });
147147
expect(Profiles).not.to.have.been.called;
148148
expect(Profile).not.to.have.been.called;
149149
expect(Fallback).not.to.have.been.called;
@@ -159,7 +159,7 @@ describe('Router', () => {
159159

160160
expect(scratch).to.have.property('textContent', 'Profiles');
161161
expect(Home).not.to.have.been.called;
162-
expect(Profiles).to.have.been.calledWith({ path: '/profiles', searchParams: {}, pathParams: {}, rest: '' });
162+
expect(Profiles).to.have.been.calledWith({ path: '/profiles', searchParams: {}, pathParams: {} });
163163
expect(Profile).not.to.have.been.called;
164164
expect(Fallback).not.to.have.been.called;
165165

@@ -177,7 +177,7 @@ describe('Router', () => {
177177
expect(Home).not.to.have.been.called;
178178
expect(Profiles).not.to.have.been.called;
179179
expect(Profile).to.have.been.calledWith(
180-
{ path: '/profiles/bob', searchParams: {}, pathParams: { id: 'bob' }, id: 'bob', rest: '' },
180+
{ path: '/profiles/bob', searchParams: {}, pathParams: { id: 'bob' }, id: 'bob' },
181181
);
182182
expect(Fallback).not.to.have.been.called;
183183

@@ -196,7 +196,7 @@ describe('Router', () => {
196196
expect(Profiles).not.to.have.been.called;
197197
expect(Profile).not.to.have.been.called;
198198
expect(Fallback).to.have.been.calledWith(
199-
{ default: true, path: '/other', searchParams: { a: 'b', c: 'd' }, pathParams: {}, rest: '' },
199+
{ default: true, path: '/other', searchParams: { a: 'b', c: 'd' }, pathParams: {} },
200200
);
201201

202202
expect(loc).to.deep.include({
@@ -233,13 +233,13 @@ describe('Router', () => {
233233
);
234234

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

238238
A.resetHistory();
239239
await sleep(10);
240240

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

244244
A.resetHistory();
245245
loc.route('/b');
@@ -253,14 +253,14 @@ describe('Router', () => {
253253
// We should never re-invoke <A /> while loading <B /> (that would be a remount of the old route):
254254
// ...but we do
255255
//expect(A).not.to.have.been.called;
256-
expect(B).to.have.been.calledWith({ path: '/b', searchParams: {}, pathParams: {}, rest: '' });
256+
expect(B).to.have.been.calledWith({ path: '/b', searchParams: {}, pathParams: {} });
257257

258258
B.resetHistory();
259259
await sleep(10);
260260

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

265265
B.resetHistory();
266266
loc.route('/c');
@@ -280,14 +280,14 @@ describe('Router', () => {
280280
// We should never re-invoke <B /> while loading <C /> (that would be a remount of the old route):
281281
// ...but we do
282282
//expect(B).not.to.have.been.called;
283-
expect(C).to.have.been.calledWith({ path: '/c', searchParams: {}, pathParams: {}, rest: '' });
283+
expect(C).to.have.been.calledWith({ path: '/c', searchParams: {}, pathParams: {} });
284284

285285
C.resetHistory();
286286
await sleep(10);
287287

288288
expect(scratch).to.have.property('innerHTML', '<h1>C</h1>');
289289
expect(C).to.have.been.calledOnce;
290-
expect(C).to.have.been.calledWith({ path: '/c', searchParams: {}, pathParams: {}, rest: '' });
290+
expect(C).to.have.been.calledWith({ path: '/c', searchParams: {}, pathParams: {} });
291291

292292
// "instant" routing to already-loaded routes
293293

@@ -299,7 +299,7 @@ describe('Router', () => {
299299
expect(scratch).to.have.property('innerHTML', '<h1>B</h1><p>hello</p>');
300300
expect(C).not.to.have.been.called;
301301
expect(B).to.have.been.calledOnce;
302-
expect(B).to.have.been.calledWith({ path: '/b', searchParams: {}, pathParams: {}, rest: '' });
302+
expect(B).to.have.been.calledWith({ path: '/b', searchParams: {}, pathParams: {} });
303303

304304
A.resetHistory();
305305
B.resetHistory();
@@ -309,7 +309,7 @@ describe('Router', () => {
309309
expect(scratch).to.have.property('innerHTML', '<h1>A</h1><p>hello</p>');
310310
expect(B).not.to.have.been.called;
311311
expect(A).to.have.been.calledOnce;
312-
expect(A).to.have.been.calledWith({ path: '/', searchParams: {}, pathParams: {}, rest: '' });
312+
expect(A).to.have.been.calledWith({ path: '/', searchParams: {}, pathParams: {} });
313313
});
314314

315315
it('rerenders same-component routes rather than swap', async () => {
@@ -398,7 +398,7 @@ describe('Router', () => {
398398
);
399399

400400
expect(scratch).to.have.property('innerHTML', '');
401-
expect(A).to.have.been.calledWith({ path: '/', searchParams: {}, pathParams: {}, rest: '' });
401+
expect(A).to.have.been.calledWith({ path: '/', searchParams: {}, pathParams: {} });
402402
expect(loadStart).to.have.been.calledWith('/');
403403
expect(loadEnd).not.to.have.been.called;
404404
expect(routeChange).not.to.have.been.called;
@@ -410,7 +410,7 @@ describe('Router', () => {
410410
await sleep(1);
411411

412412
expect(scratch).to.have.property('innerHTML', '<h1>A</h1><p>hello</p>');
413-
expect(A).to.have.been.calledWith({ path: '/', searchParams: {}, pathParams: {}, rest: '' });
413+
expect(A).to.have.been.calledWith({ path: '/', searchParams: {}, pathParams: {} });
414414
expect(loadStart).not.to.have.been.called;
415415
expect(loadEnd).to.have.been.calledWith('/');
416416
expect(routeChange).not.to.have.been.called;
@@ -931,7 +931,7 @@ describe('hydration', () => {
931931
mutationObserver.observe(scratch, { childList: true, subtree: true });
932932

933933
expect(scratch).to.have.property('innerHTML', '<div><h1>A</h1><p>hello</p></div>');
934-
expect(A).to.have.been.calledWith({ path: '/', searchParams: {}, pathParams: {}, rest: '' });
934+
expect(A).to.have.been.calledWith({ path: '/', searchParams: {}, pathParams: {} });
935935
const oldOptionsVnode = options.__b;
936936
let hasMatched = false;
937937
options.__b = (vnode) => {
@@ -955,7 +955,7 @@ describe('hydration', () => {
955955
await sleep(10);
956956

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

961961
options.__b = oldOptionsVnode;

0 commit comments

Comments
 (0)