Skip to content

Commit 70b0112

Browse files
authored
Merge branch '2.x' into improve/route-url-branded-type
2 parents c2c379b + 8a0b645 commit 70b0112

File tree

9 files changed

+42
-19
lines changed

9 files changed

+42
-19
lines changed

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ Breaking changes are marked with ⚠️.
88

99
## [Unreleased]
1010

11+
## [v2.6.2] - 2026-03-05
12+
13+
**Fixed**
14+
15+
* Fix shared route bindings mutation in _substituteBindings by @pataar in https://github.com/tighten/ziggy/pull/875
16+
* fix: handle falsy parameter values in _parse by @pataar in https://github.com/tighten/ziggy/pull/876
17+
1118
## [v2.6.1] - 2026-02-16
1219

1320
**Changed**
@@ -510,7 +517,8 @@ See [UPGRADING](UPGRADING.md#upgrading-from-1x-to-2x) for detailed upgrade instr
510517

511518
For previous changes see the [Releases](https://github.com/tighten/ziggy/releases) page.
512519

513-
[Unreleased]: https://github.com/tighten/ziggy/compare/v2.6.1...HEAD
520+
[Unreleased]: https://github.com/tighten/ziggy/compare/v2.6.2...HEAD
521+
[v2.6.2]: https://github.com/tighten/ziggy/compare/v2.6.1...v2.6.2
514522
[v2.6.1]: https://github.com/tighten/ziggy/compare/v2.6.0...v2.6.1
515523
[v2.6.0]: https://github.com/tighten/ziggy/compare/v2.5.3...v2.6.0
516524
[v2.5.3]: https://github.com/tighten/ziggy/compare/v2.5.2...v2.5.3

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# Ziggy – Use your Laravel routes in JavaScript
44

5-
[![GitHub Actions Status](https://img.shields.io/github/actions/workflow/status/tighten/ziggy/test.yml?branch=main&style=flat)](https://github.com/tighten/ziggy/actions?query=workflow:Tests+branch:main)
5+
[![GitHub Actions Status](https://img.shields.io/github/actions/workflow/status/tighten/ziggy/test.yml?branch=main&style=flat)](https://github.com/tighten/ziggy/actions?query=workflow:Test+branch:2.x)
66
[![Latest Version on Packagist](https://img.shields.io/packagist/v/tightenco/ziggy.svg?style=flat)](https://packagist.org/packages/tightenco/ziggy)
77
[![Downloads on Packagist](https://img.shields.io/packagist/dt/tightenco/ziggy.svg?style=flat)](https://packagist.org/packages/tightenco/ziggy)
88
[![Latest Version on NPM](https://img.shields.io/npm/v/ziggy-js.svg?style=flat)](https://npmjs.com/package/ziggy-js)

dist/index.esm.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/route.umd.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ziggy-js",
3-
"version": "2.6.1",
3+
"version": "2.6.2",
44
"description": "Use your Laravel named routes in JavaScript.",
55
"keywords": [
66
"laravel",

src/js/Router.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ export default class Router extends String {
263263
);
264264
} else if (
265265
segments.length === 1 &&
266-
!params[segments[0].name] &&
266+
!params.hasOwnProperty(segments[0].name) &&
267267
(params.hasOwnProperty(Object.values(route.bindings)[0]) || params.hasOwnProperty('id'))
268268
) {
269269
// If there is only one template segment and `params` is an object, that object is
@@ -321,18 +321,19 @@ export default class Router extends String {
321321
return { ...result, [key]: value };
322322
}
323323

324-
if (!value.hasOwnProperty(bindings[key])) {
325-
if (value.hasOwnProperty('id')) {
326-
// As a fallback, we still accept an 'id' key not explicitly registered as a binding
327-
bindings[key] = 'id';
328-
} else {
329-
throw new Error(
330-
`Ziggy error: object passed as '${key}' parameter is missing route model binding key '${bindings[key]}'.`,
331-
);
332-
}
324+
const binding = value.hasOwnProperty(bindings[key])
325+
? bindings[key]
326+
: value.hasOwnProperty('id')
327+
? 'id'
328+
: undefined;
329+
330+
if (binding === undefined) {
331+
throw new Error(
332+
`Ziggy error: object passed as '${key}' parameter is missing route model binding key '${bindings[key]}'.`,
333+
);
333334
}
334335

335-
return { ...result, [key]: value[bindings[key]] };
336+
return { ...result, [key]: value[binding] };
336337
}, {});
337338
}
338339

tests/js/route.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,16 @@ describe('route()', () => {
437437
);
438438
});
439439

440+
test("falling back to 'id' key does not mutate registered route model bindings", () => {
441+
expect(route('postComments.show', [1, { id: 1 }])).toBe(
442+
'https://ziggy.dev/posts/1/comments/1',
443+
);
444+
445+
expect(route('postComments.show', [1, { id: 1, uuid: '1-2-3' }])).toBe(
446+
'https://ziggy.dev/posts/1/comments/1-2-3',
447+
);
448+
});
449+
440450
test('can generate a URL for an app installed in a subfolder', () => {
441451
global.Ziggy.url = 'https://ziggy.dev/subfolder';
442452

@@ -593,6 +603,10 @@ describe('route()', () => {
593603
expect(route('posts.update', 0)).toBe('https://ziggy.dev/posts/0');
594604
});
595605

606+
test('can handle an object parameter with a falsy value for the segment name', () => {
607+
expect(route('posts.show', { post: 0 })).toBe('https://ziggy.dev/posts/0');
608+
});
609+
596610
test('can accept a custom Ziggy configuration object', () => {
597611
const config = {
598612
url: 'http://notYourAverage.dev',

0 commit comments

Comments
 (0)