|
| 1 | +/** |
| 2 | + * The official Router for Vue 3. |
| 3 | + * |
| 4 | + * @packageDocumentation |
| 5 | + */ |
| 6 | + |
1 | 7 | export { createWebHistory } from './history/html5'
|
2 | 8 | export { createMemoryHistory } from './history/memory'
|
3 | 9 | export { createWebHashHistory } from './history/hash'
|
@@ -167,10 +173,82 @@ export type { TypesConfig } from './config'
|
167 | 173 |
|
168 | 174 | export * from './useApi'
|
169 | 175 |
|
170 |
| -export * from './globalExtensions' |
| 176 | +// Global extensions for Vue |
| 177 | +import type { TypesConfig } from './config' |
| 178 | +import type { Router } from './router' |
| 179 | +import type { RouterLink } from './RouterLink' |
| 180 | +import type { RouterView } from './RouterView' |
| 181 | +import type { |
| 182 | + NavigationGuard, |
| 183 | + NavigationGuardWithThis, |
| 184 | + RouteLocationNormalizedLoaded, |
| 185 | +} from './typed-routes' |
171 | 186 |
|
172 |
| -/** |
173 |
| - * The official Router for Vue 3. |
174 |
| - * |
175 |
| - * @packageDocumentation |
176 |
| - */ |
| 187 | +declare module 'vue' { |
| 188 | + export interface ComponentCustomOptions { |
| 189 | + /** |
| 190 | + * Guard called when the router is navigating to the route that is rendering |
| 191 | + * this component from a different route. Differently from `beforeRouteUpdate` |
| 192 | + * and `beforeRouteLeave`, `beforeRouteEnter` does not have access to the |
| 193 | + * component instance through `this` because it triggers before the component |
| 194 | + * is even mounted. |
| 195 | + * |
| 196 | + * @param to - RouteLocationRaw we are navigating to |
| 197 | + * @param from - RouteLocationRaw we are navigating from |
| 198 | + * @param next - function to validate, cancel or modify (by redirecting) the |
| 199 | + * navigation |
| 200 | + */ |
| 201 | + beforeRouteEnter?: TypesConfig extends Record<'beforeRouteEnter', infer T> |
| 202 | + ? T |
| 203 | + : NavigationGuardWithThis<undefined> |
| 204 | + |
| 205 | + /** |
| 206 | + * Guard called whenever the route that renders this component has changed, but |
| 207 | + * it is reused for the new route. This allows you to guard for changes in |
| 208 | + * params, the query or the hash. |
| 209 | + * |
| 210 | + * @param to - RouteLocationRaw we are navigating to |
| 211 | + * @param from - RouteLocationRaw we are navigating from |
| 212 | + * @param next - function to validate, cancel or modify (by redirecting) the |
| 213 | + * navigation |
| 214 | + */ |
| 215 | + beforeRouteUpdate?: TypesConfig extends Record<'beforeRouteUpdate', infer T> |
| 216 | + ? T |
| 217 | + : NavigationGuard |
| 218 | + |
| 219 | + /** |
| 220 | + * Guard called when the router is navigating away from the current route that |
| 221 | + * is rendering this component. |
| 222 | + * |
| 223 | + * @param to - RouteLocationRaw we are navigating to |
| 224 | + * @param from - RouteLocationRaw we are navigating from |
| 225 | + * @param next - function to validate, cancel or modify (by redirecting) the |
| 226 | + * navigation |
| 227 | + */ |
| 228 | + beforeRouteLeave?: TypesConfig extends Record<'beforeRouteLeave', infer T> |
| 229 | + ? T |
| 230 | + : NavigationGuard |
| 231 | + } |
| 232 | + |
| 233 | + export interface ComponentCustomProperties { |
| 234 | + /** |
| 235 | + * Normalized current location. See {@link RouteLocationNormalizedLoaded}. |
| 236 | + */ |
| 237 | + $route: TypesConfig extends Record<'$route', infer T> |
| 238 | + ? T |
| 239 | + : RouteLocationNormalizedLoaded |
| 240 | + /** |
| 241 | + * {@link Router} instance used by the application. |
| 242 | + */ |
| 243 | + $router: TypesConfig extends Record<'$router', infer T> ? T : Router |
| 244 | + } |
| 245 | + |
| 246 | + export interface GlobalComponents { |
| 247 | + RouterView: TypesConfig extends Record<'RouterView', infer T> |
| 248 | + ? T |
| 249 | + : typeof RouterView |
| 250 | + RouterLink: TypesConfig extends Record<'RouterLink', infer T> |
| 251 | + ? T |
| 252 | + : typeof RouterLink |
| 253 | + } |
| 254 | +} |
0 commit comments