ziggy-js 2.3.1 → 2.4.0
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/README.md +11 -1
- package/package.json +3 -2
- package/src/js/index.d.ts +21 -9
package/README.md
CHANGED
|
@@ -44,7 +44,7 @@ Add the `@routes` Blade directive to your main layout (_before_ your application
|
|
|
44
44
|
|
|
45
45
|
### `route()` function
|
|
46
46
|
|
|
47
|
-
Ziggy's `route()` function works like [Laravel's `route()` helper](https://laravel.com/docs/
|
|
47
|
+
Ziggy's `route()` function works like [Laravel's `route()` helper](https://laravel.com/docs/helpers#method-route)—you can pass it the name of a route, and the parameters you want to pass to the route, and it will generate a URL.
|
|
48
48
|
|
|
49
49
|
#### Basic usage
|
|
50
50
|
|
|
@@ -378,6 +378,16 @@ Now you can use the `route()` function anywhere in your Vue components and templ
|
|
|
378
378
|
<a class="nav-link" :href="route('home')">Home</a>
|
|
379
379
|
```
|
|
380
380
|
|
|
381
|
+
With `<script setup>` in Vue 3 you can use `inject` to make the `route()` function available in your component script:
|
|
382
|
+
|
|
383
|
+
```vue
|
|
384
|
+
<script setup>
|
|
385
|
+
import { inject } from 'vue';
|
|
386
|
+
|
|
387
|
+
const route = inject('route');
|
|
388
|
+
</script>
|
|
389
|
+
```
|
|
390
|
+
|
|
381
391
|
If you are not using the `@routes` Blade directive, import Ziggy's configuration too and pass it to `.use()`:
|
|
382
392
|
|
|
383
393
|
```js
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ziggy-js",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0",
|
|
4
4
|
"description": "Use your Laravel named routes in JavaScript.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"laravel",
|
|
@@ -56,11 +56,12 @@
|
|
|
56
56
|
"qs": "~6.9.7"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
+
"@types/qs": "^6.9.17",
|
|
59
60
|
"jsdom": "^25.0.1",
|
|
60
61
|
"microbundle": "^0.15.1",
|
|
61
62
|
"prettier": "^3.3.3",
|
|
62
63
|
"typescript": "^5.6.3",
|
|
63
|
-
"vitest": "^2.1.
|
|
64
|
+
"vitest": "^2.1.4"
|
|
64
65
|
},
|
|
65
66
|
"prettier": {
|
|
66
67
|
"printWidth": 100,
|
package/src/js/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { ParsedQs } from 'qs';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* A list of routes and their parameters and bindings.
|
|
3
5
|
*
|
|
@@ -5,6 +7,11 @@
|
|
|
5
7
|
*/
|
|
6
8
|
export interface RouteList {}
|
|
7
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Marker interface to configure Ziggy's type checking behavior.
|
|
12
|
+
*/
|
|
13
|
+
export interface TypeConfig {}
|
|
14
|
+
|
|
8
15
|
/**
|
|
9
16
|
* A route name registered with Ziggy.
|
|
10
17
|
*/
|
|
@@ -13,7 +20,9 @@ type KnownRouteName = keyof RouteList;
|
|
|
13
20
|
/**
|
|
14
21
|
* A route name, or any string.
|
|
15
22
|
*/
|
|
16
|
-
type RouteName =
|
|
23
|
+
type RouteName = TypeConfig extends { strictRouteNames: true }
|
|
24
|
+
? KnownRouteName
|
|
25
|
+
: KnownRouteName | (string & {});
|
|
17
26
|
// `(string & {})` prevents TypeScript from reducing this type to just `string`,
|
|
18
27
|
// which would prevent intellisense from autocompleting known route names.
|
|
19
28
|
// See https://stackoverflow.com/a/61048124/6484459.
|
|
@@ -159,7 +168,7 @@ interface Router {
|
|
|
159
168
|
current<T extends RouteName>(name: T, params?: ParameterValue | RouteParams<T>): boolean;
|
|
160
169
|
get params(): Record<string, string>;
|
|
161
170
|
get routeParams(): Record<string, string>;
|
|
162
|
-
get queryParams():
|
|
171
|
+
get queryParams(): ParsedQs;
|
|
163
172
|
has<T extends RouteName>(name: T): boolean;
|
|
164
173
|
}
|
|
165
174
|
|
|
@@ -168,6 +177,15 @@ interface Router {
|
|
|
168
177
|
*/
|
|
169
178
|
// Called with no arguments - returns a Router instance
|
|
170
179
|
export function route(): Router;
|
|
180
|
+
|
|
181
|
+
// Called with configuration arguments only - returns a configured Router instance
|
|
182
|
+
export function route(
|
|
183
|
+
name: undefined,
|
|
184
|
+
params: undefined,
|
|
185
|
+
absolute?: boolean,
|
|
186
|
+
config?: Config,
|
|
187
|
+
): Router;
|
|
188
|
+
|
|
171
189
|
// Called with a route name and optional additional arguments - returns a URL string
|
|
172
190
|
export function route<T extends RouteName>(
|
|
173
191
|
name: T,
|
|
@@ -175,19 +193,13 @@ export function route<T extends RouteName>(
|
|
|
175
193
|
absolute?: boolean,
|
|
176
194
|
config?: Config,
|
|
177
195
|
): string;
|
|
196
|
+
|
|
178
197
|
export function route<T extends RouteName>(
|
|
179
198
|
name: T,
|
|
180
199
|
params?: ParameterValue | undefined,
|
|
181
200
|
absolute?: boolean,
|
|
182
201
|
config?: Config,
|
|
183
202
|
): string;
|
|
184
|
-
// Called with configuration arguments only - returns a configured Router instance
|
|
185
|
-
export function route(
|
|
186
|
-
name: undefined,
|
|
187
|
-
params: undefined,
|
|
188
|
-
absolute?: boolean,
|
|
189
|
-
config?: Config,
|
|
190
|
-
): Router;
|
|
191
203
|
|
|
192
204
|
/**
|
|
193
205
|
* Ziggy's Vue plugin.
|