nuxt-typed-router 2.1.0-beta.2 → 2.1.0-beta.4
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/dist/module.json +1 -1
- package/dist/module.mjs +14 -16
- package/package.json +1 -1
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -26,8 +26,8 @@ import type {
|
|
|
26
26
|
TypedRouteParams,
|
|
27
27
|
ResolvedTypedRouteNamedMapper,
|
|
28
28
|
} from './__routes';
|
|
29
|
-
import {
|
|
30
|
-
import {
|
|
29
|
+
import {useRoute as _useRoute} from './__useTypedRoute';
|
|
30
|
+
import {useRouter as _useRouter} from './__useTypedRouter';
|
|
31
31
|
`;
|
|
32
32
|
|
|
33
33
|
const watermarkTemplate = `
|
|
@@ -133,8 +133,8 @@ function createRuntimeTypeUtils(autoImport) {
|
|
|
133
133
|
export type TypedRoute = _TypedRoute;
|
|
134
134
|
export type TypedNamedRoute<T extends TypedRouteList> = _TypedNamedRoute<T>;
|
|
135
135
|
|
|
136
|
-
${autoImport ? `const useRoute: typeof
|
|
137
|
-
const useRouter: typeof
|
|
136
|
+
${autoImport ? `const useRoute: typeof _useRoute;
|
|
137
|
+
const useRouter: typeof _useRouter;` : ""}
|
|
138
138
|
}
|
|
139
139
|
|
|
140
140
|
type TypedNuxtLinkProps = Omit<NuxtLinkProps, 'to'> & {
|
|
@@ -281,7 +281,7 @@ function createRuntimeRoutesFile({
|
|
|
281
281
|
function createUseTypedRouteFile(routesDeclTemplate) {
|
|
282
282
|
return `
|
|
283
283
|
${watermarkTemplate}
|
|
284
|
-
import { useRoute } from '#app';
|
|
284
|
+
import { useRoute as defaultRoute } from '#app';
|
|
285
285
|
import type { TypedRouteList } from './__routes';
|
|
286
286
|
|
|
287
287
|
/** Acts the same as \`useRoute\`, but typed.
|
|
@@ -289,30 +289,29 @@ function createUseTypedRouteFile(routesDeclTemplate) {
|
|
|
289
289
|
* @exemple
|
|
290
290
|
*
|
|
291
291
|
* \`\`\`ts
|
|
292
|
-
* const route =
|
|
292
|
+
* const route = useRoute();
|
|
293
293
|
* \`\`\`
|
|
294
294
|
*
|
|
295
295
|
* \`\`\`ts
|
|
296
|
-
* const route =
|
|
296
|
+
* const route = useRoute('my-route-with-param-id');
|
|
297
297
|
* route.params.id // autocompletes!
|
|
298
298
|
* \`\`\`
|
|
299
299
|
*
|
|
300
300
|
* \`\`\`ts
|
|
301
|
-
* const route =
|
|
301
|
+
* const route = useRoute();
|
|
302
302
|
* if (route.name === 'my-route-with-param-id') {
|
|
303
303
|
* route.params.id // autocompletes!
|
|
304
304
|
* }
|
|
305
305
|
* \`\`\`
|
|
306
306
|
*/
|
|
307
|
-
export function
|
|
307
|
+
export function useRoute<T extends TypedRouteList = never>(
|
|
308
308
|
name?: T
|
|
309
309
|
): [T] extends [never] ? TypedRoute : TypedNamedRoute<T> {
|
|
310
|
-
const route =
|
|
310
|
+
const route = defaultRoute();
|
|
311
311
|
|
|
312
312
|
return route as any;
|
|
313
313
|
}
|
|
314
314
|
|
|
315
|
-
export const useRoute = useTypedRoute;
|
|
316
315
|
|
|
317
316
|
`;
|
|
318
317
|
}
|
|
@@ -320,7 +319,7 @@ export const useRoute = useTypedRoute;
|
|
|
320
319
|
function createRuntimeUseTypedRouterFile(routesDeclTemplate) {
|
|
321
320
|
return `
|
|
322
321
|
${watermarkTemplate}
|
|
323
|
-
import { useRouter } from '#app';
|
|
322
|
+
import { useRouter as defaultRouter } from '#app';
|
|
324
323
|
import type { TypedRouter } from './typed-router';
|
|
325
324
|
|
|
326
325
|
/** Returns instances of $typedRouter and $routesList fully typed to use in your components or your Vuex/Pinia store
|
|
@@ -328,16 +327,15 @@ function createRuntimeUseTypedRouterFile(routesDeclTemplate) {
|
|
|
328
327
|
* @exemple
|
|
329
328
|
*
|
|
330
329
|
* \`\`\`ts
|
|
331
|
-
* const { router, routes } =
|
|
330
|
+
* const { router, routes } = useRouter();
|
|
332
331
|
* \`\`\`
|
|
333
332
|
*/
|
|
334
|
-
export function
|
|
335
|
-
const router =
|
|
333
|
+
export function useRouter(): TypedRouter {
|
|
334
|
+
const router = defaultRouter();
|
|
336
335
|
|
|
337
336
|
return router;
|
|
338
337
|
};
|
|
339
338
|
|
|
340
|
-
export const useRouter = useTypedRouter;
|
|
341
339
|
`;
|
|
342
340
|
}
|
|
343
341
|
|