Skip to content

Commit d365844

Browse files
committed
refactor: Remove unused rest route param
1 parent 379f6e6 commit d365844

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
@@ -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

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

7171
expect(scratch).to.have.property('textContent', 'Home');
72-
expect(Home).to.have.been.calledWith({ path: '/', searchParams: {}, pathParams: {}, rest: '', test: '2' });
72+
expect(Home).to.have.been.calledWith({ path: '/', searchParams: {}, pathParams: {}, test: '2' });
7373
expect(loc).to.deep.include({
7474
url: '/',
7575
path: '/',
@@ -98,7 +98,7 @@ describe('Router', () => {
9898
render(<App />, scratch);
9999

100100
expect(scratch).to.have.property('textContent', 'Home');
101-
expect(Home).to.have.been.calledWith({ path: '/', searchParams: {}, pathParams: {}, rest: '', test: '2' });
101+
expect(Home).to.have.been.calledWith({ path: '/', searchParams: {}, pathParams: {}, test: '2' });
102102
expect(loc).to.deep.include({
103103
url: '/',
104104
path: '/',
@@ -108,7 +108,7 @@ describe('Router', () => {
108108
set('3')
109109
await sleep(1);
110110

111-
expect(Home).to.have.been.calledWith({ path: '/', searchParams: {}, pathParams: {}, rest: '', test: '3' });
111+
expect(Home).to.have.been.calledWith({ path: '/', searchParams: {}, pathParams: {}, test: '3' });
112112
expect(loc).to.deep.include({
113113
url: '/',
114114
path: '/',
@@ -138,7 +138,7 @@ describe('Router', () => {
138138
);
139139

140140
expect(scratch).to.have.property('textContent', 'Home');
141-
expect(Home).to.have.been.calledWith({ path: '/', searchParams: {}, pathParams: {}, rest: '' });
141+
expect(Home).to.have.been.calledWith({ path: '/', searchParams: {}, pathParams: {} });
142142
expect(Profiles).not.to.have.been.called;
143143
expect(Profile).not.to.have.been.called;
144144
expect(Fallback).not.to.have.been.called;
@@ -154,7 +154,7 @@ describe('Router', () => {
154154

155155
expect(scratch).to.have.property('textContent', 'Profiles');
156156
expect(Home).not.to.have.been.called;
157-
expect(Profiles).to.have.been.calledWith({ path: '/profiles', searchParams: {}, pathParams: {}, rest: '' });
157+
expect(Profiles).to.have.been.calledWith({ path: '/profiles', searchParams: {}, pathParams: {} });
158158
expect(Profile).not.to.have.been.called;
159159
expect(Fallback).not.to.have.been.called;
160160

@@ -172,7 +172,7 @@ describe('Router', () => {
172172
expect(Home).not.to.have.been.called;
173173
expect(Profiles).not.to.have.been.called;
174174
expect(Profile).to.have.been.calledWith(
175-
{ path: '/profiles/bob', searchParams: {}, pathParams: { id: 'bob' }, id: 'bob', rest: '' },
175+
{ path: '/profiles/bob', searchParams: {}, pathParams: { id: 'bob' }, id: 'bob' },
176176
);
177177
expect(Fallback).not.to.have.been.called;
178178

@@ -191,7 +191,7 @@ describe('Router', () => {
191191
expect(Profiles).not.to.have.been.called;
192192
expect(Profile).not.to.have.been.called;
193193
expect(Fallback).to.have.been.calledWith(
194-
{ default: true, path: '/other', searchParams: { a: 'b', c: 'd' }, pathParams: {}, rest: '' },
194+
{ default: true, path: '/other', searchParams: { a: 'b', c: 'd' }, pathParams: {} },
195195
);
196196

197197
expect(loc).to.deep.include({
@@ -228,13 +228,13 @@ describe('Router', () => {
228228
);
229229

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

233233
A.resetHistory();
234234
await sleep(10);
235235

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

239239
A.resetHistory();
240240
loc.route('/b');
@@ -248,14 +248,14 @@ describe('Router', () => {
248248
// We should never re-invoke <A /> while loading <B /> (that would be a remount of the old route):
249249
// ...but we do
250250
//expect(A).not.to.have.been.called;
251-
expect(B).to.have.been.calledWith({ path: '/b', searchParams: {}, pathParams: {}, rest: '' });
251+
expect(B).to.have.been.calledWith({ path: '/b', searchParams: {}, pathParams: {} });
252252

253253
B.resetHistory();
254254
await sleep(10);
255255

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

260260
B.resetHistory();
261261
loc.route('/c');
@@ -275,14 +275,14 @@ describe('Router', () => {
275275
// We should never re-invoke <B /> while loading <C /> (that would be a remount of the old route):
276276
// ...but we do
277277
//expect(B).not.to.have.been.called;
278-
expect(C).to.have.been.calledWith({ path: '/c', searchParams: {}, pathParams: {}, rest: '' });
278+
expect(C).to.have.been.calledWith({ path: '/c', searchParams: {}, pathParams: {} });
279279

280280
C.resetHistory();
281281
await sleep(10);
282282

283283
expect(scratch).to.have.property('innerHTML', '<h1>C</h1>');
284284
expect(C).to.have.been.calledOnce;
285-
expect(C).to.have.been.calledWith({ path: '/c', searchParams: {}, pathParams: {}, rest: '' });
285+
expect(C).to.have.been.calledWith({ path: '/c', searchParams: {}, pathParams: {} });
286286

287287
// "instant" routing to already-loaded routes
288288

@@ -294,7 +294,7 @@ describe('Router', () => {
294294
expect(scratch).to.have.property('innerHTML', '<h1>B</h1><p>hello</p>');
295295
expect(C).not.to.have.been.called;
296296
expect(B).to.have.been.calledOnce;
297-
expect(B).to.have.been.calledWith({ path: '/b', searchParams: {}, pathParams: {}, rest: '' });
297+
expect(B).to.have.been.calledWith({ path: '/b', searchParams: {}, pathParams: {} });
298298

299299
A.resetHistory();
300300
B.resetHistory();
@@ -304,7 +304,7 @@ describe('Router', () => {
304304
expect(scratch).to.have.property('innerHTML', '<h1>A</h1><p>hello</p>');
305305
expect(B).not.to.have.been.called;
306306
expect(A).to.have.been.calledOnce;
307-
expect(A).to.have.been.calledWith({ path: '/', searchParams: {}, pathParams: {}, rest: '' });
307+
expect(A).to.have.been.calledWith({ path: '/', searchParams: {}, pathParams: {} });
308308
});
309309

310310
it('rerenders same-component routes rather than swap', async () => {
@@ -395,7 +395,7 @@ describe('Router', () => {
395395
);
396396

397397
expect(scratch).to.have.property('innerHTML', '');
398-
expect(A).to.have.been.calledWith({ path: '/', searchParams: {}, pathParams: {}, rest: '' });
398+
expect(A).to.have.been.calledWith({ path: '/', searchParams: {}, pathParams: {} });
399399
expect(loadStart).to.have.been.calledWith('/');
400400
expect(loadEnd).not.to.have.been.called;
401401
expect(routeChange).not.to.have.been.called;
@@ -407,7 +407,7 @@ describe('Router', () => {
407407
await sleep(10);
408408

409409
expect(scratch).to.have.property('innerHTML', '<h1>A</h1><p>hello</p>');
410-
expect(A).to.have.been.calledWith({ path: '/', searchParams: {}, pathParams: {}, rest: '' });
410+
expect(A).to.have.been.calledWith({ path: '/', searchParams: {}, pathParams: {} });
411411
expect(loadStart).not.to.have.been.called;
412412
expect(loadEnd).to.have.been.calledWith('/');
413413
expect(routeChange).not.to.have.been.called;
@@ -947,7 +947,7 @@ describe('hydration', () => {
947947
mutationObserver.observe(scratch, { childList: true, subtree: true });
948948

949949
expect(scratch).to.have.property('innerHTML', '<div><h1>A</h1><p>hello</p></div>');
950-
expect(A).to.have.been.calledWith({ path: '/', searchParams: {}, pathParams: {}, rest: '' });
950+
expect(A).to.have.been.calledWith({ path: '/', searchParams: {}, pathParams: {} });
951951
const oldOptionsVnode = options.__b;
952952
let hasMatched = false;
953953
options.__b = (vnode) => {
@@ -971,7 +971,7 @@ describe('hydration', () => {
971971
await sleep(10);
972972

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

977977
options.__b = oldOptionsVnode;

0 commit comments

Comments
 (0)