@real-router/vue 0.10.0 → 0.11.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 +9 -0
- package/dist/cjs/index.d.ts +21 -0
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.d.mts +21 -0
- package/dist/esm/index.d.mts.map +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/index.mjs.map +1 -1
- package/package.json +5 -5
- package/src/components/Link.ts +41 -10
- package/src/composables/useIsActiveRoute.ts +12 -4
package/src/components/Link.ts
CHANGED
|
@@ -3,7 +3,12 @@ import { defineComponent, h, computed, shallowRef, watch } from "vue";
|
|
|
3
3
|
|
|
4
4
|
import { useRouter } from "../composables/useRouter";
|
|
5
5
|
import { EMPTY_PARAMS, EMPTY_OPTIONS } from "../constants";
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
shouldNavigate,
|
|
8
|
+
buildHref,
|
|
9
|
+
buildActiveClassName,
|
|
10
|
+
navigateWithHash,
|
|
11
|
+
} from "../dom-utils";
|
|
7
12
|
|
|
8
13
|
import type { Params, NavigationOptions } from "@real-router/core";
|
|
9
14
|
import type { PropType } from "vue";
|
|
@@ -75,6 +80,16 @@ export const Link = defineComponent({
|
|
|
75
80
|
type: String,
|
|
76
81
|
default: undefined,
|
|
77
82
|
},
|
|
83
|
+
/**
|
|
84
|
+
* URL fragment (decoded form, no leading "#") (#532).
|
|
85
|
+
* - omitted/`undefined` → preserve current fragment on same-route navigation
|
|
86
|
+
* - `""` → clear fragment
|
|
87
|
+
* - non-empty → set fragment
|
|
88
|
+
*/
|
|
89
|
+
hash: {
|
|
90
|
+
type: String,
|
|
91
|
+
default: undefined,
|
|
92
|
+
},
|
|
78
93
|
},
|
|
79
94
|
setup(props, { slots, attrs }) {
|
|
80
95
|
const router = useRouter();
|
|
@@ -92,16 +107,23 @@ export const Link = defineComponent({
|
|
|
92
107
|
props.routeParams,
|
|
93
108
|
props.activeStrict,
|
|
94
109
|
props.ignoreQueryParams,
|
|
110
|
+
props.hash,
|
|
95
111
|
] as const,
|
|
96
112
|
(
|
|
97
|
-
[routeName, routeParams, activeStrict, ignoreQueryParams],
|
|
113
|
+
[routeName, routeParams, activeStrict, ignoreQueryParams, hash],
|
|
98
114
|
_prev,
|
|
99
115
|
onCleanup,
|
|
100
116
|
) => {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
117
|
+
// Hash-aware active (#532): pass hash through so tab links with the
|
|
118
|
+
// same routeName but different `hash` props don't all light up.
|
|
119
|
+
const source = createActiveRouteSource(
|
|
120
|
+
router,
|
|
121
|
+
routeName,
|
|
122
|
+
routeParams,
|
|
123
|
+
hash === undefined
|
|
124
|
+
? { strict: activeStrict, ignoreQueryParams }
|
|
125
|
+
: { strict: activeStrict, ignoreQueryParams, hash },
|
|
126
|
+
);
|
|
105
127
|
|
|
106
128
|
isActive.value = source.getSnapshot();
|
|
107
129
|
|
|
@@ -115,7 +137,12 @@ export const Link = defineComponent({
|
|
|
115
137
|
);
|
|
116
138
|
|
|
117
139
|
const href = computed(() =>
|
|
118
|
-
buildHref(
|
|
140
|
+
buildHref(
|
|
141
|
+
router,
|
|
142
|
+
props.routeName,
|
|
143
|
+
props.routeParams,
|
|
144
|
+
props.hash === undefined ? undefined : { hash: props.hash },
|
|
145
|
+
),
|
|
119
146
|
);
|
|
120
147
|
|
|
121
148
|
const finalClassName = computed(() =>
|
|
@@ -140,9 +167,13 @@ export const Link = defineComponent({
|
|
|
140
167
|
}
|
|
141
168
|
|
|
142
169
|
evt.preventDefault();
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
.
|
|
170
|
+
navigateWithHash(
|
|
171
|
+
router,
|
|
172
|
+
props.routeName,
|
|
173
|
+
props.routeParams,
|
|
174
|
+
props.hash,
|
|
175
|
+
props.routeOptions,
|
|
176
|
+
).catch(() => {});
|
|
146
177
|
};
|
|
147
178
|
|
|
148
179
|
return () => {
|
|
@@ -11,13 +11,21 @@ export function useIsActiveRoute(
|
|
|
11
11
|
params?: Params,
|
|
12
12
|
strict = false,
|
|
13
13
|
ignoreQueryParams = true,
|
|
14
|
+
hash?: string,
|
|
14
15
|
): ShallowRef<boolean> {
|
|
15
16
|
const router = useRouter();
|
|
16
17
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
// The `hash` argument (#532) participates in the cache key when defined.
|
|
19
|
+
// exactOptionalPropertyTypes forbids `{ hash: undefined }` literally — we
|
|
20
|
+
// conditionally include the key only when a value is provided.
|
|
21
|
+
const source = createActiveRouteSource(
|
|
22
|
+
router,
|
|
23
|
+
routeName,
|
|
24
|
+
params,
|
|
25
|
+
hash === undefined
|
|
26
|
+
? { strict, ignoreQueryParams }
|
|
27
|
+
: { strict, ignoreQueryParams, hash },
|
|
28
|
+
);
|
|
21
29
|
|
|
22
30
|
return useRefFromSource(source);
|
|
23
31
|
}
|