/** * VueRouterBridge — it connects Vue Router 4.x to RouterBridgeBase. * * The bridge uses the Vue function `watch(router.currentRoute, …)` for the * router-to-actor direction. That reactive watcher compares the values, and it * fires only on a real change of the route, not on every navigation that resolves. * This is equivalent to the `history.subscribe()` and `router.subscribe()` pattern * of the TanStack adapter and the React Router adapter. It also removes the GAP-12 * double fire, which needed a separate `lastAfterEachPath` tracker when the bridge * used `afterEach`. * * The bridge uses `router.push(path)` for the actor-to-router direction. The base * class resolves each actor route to a concrete path before it calls * `navigateRouter`. */ import type { Router } from "vue-router"; import { RouterBridgeBase } from "@xmachines/play-router"; import type { RouterBridgeOptions, RoutableActor, RouteMap } from "@xmachines/play-router"; export declare class VueRouterBridge extends RouterBridgeBase { private readonly vueRouter; /** * The separate Vue effect scope that owns the `currentRoute` watcher. * The watcher runs inside its own scope. Therefore `scope.stop()` in * `unwatchRouterChanges()` removes it completely. Nothing stays in the global * effect scope, and one test does not contaminate another test in vitest. */ private watcherScope; constructor(vueRouter: Router, actor: RoutableActor, routeMap: RouteMap, options?: RouterBridgeOptions); private normalizeQuery; /** * Converts the `route.query` object of vue-router into a URL search string for * `syncActorFromRouter`. * * The method builds the search string from `route.query`, and it does not slice the * string `route.fullPath`. This choice is deliberate: `fullPath` also holds the hash * fragment. A slice from the first `"?"` therefore puts the hash into a query value * (`/settings?tab=security#top` → `{ tab: "security#top" }`), and it reads a `"?"` * inside the hash as a query that does not exist (`/page#/sub?x=1` → `{ x: "1" }`). * * @returns The search string, for example `"?tab=security"`, or `undefined` when it is empty. */ private searchFromQuery; /** * Navigates Vue Router to the given path. * * The method receives a RESOLVED concrete URL path. The base class resolves each * stateId, and it skips a route that it cannot resolve, before it calls this * method. Therefore this method pushes the value without a change. A navigation * error becomes a {@link VueRouterNavigationError}. * * The `lastSyncedPath` field of the base class does the echo suppression, which * stops the watcher from sending the answer of the router to this push back to the * actor. `syncRouterFromActor` sets `lastSyncedPath` to the resolved path before * this call. The watcher then fires with the same path, and it stops at the * `sanitized === lastSyncedPath` check. It sends no event. */ protected navigateRouter(path: string): void; /** * Reads each path parameter of the matched route, and it prefers the values that * `route.params` of vue-router parsed before. * * Vue Router holds every named parameter of ITS OWN matched route already, and the * values are decoded. A host app that registers a real parameterized route * (`/profile/:userId`) therefore keeps that parse, with its decoding, and the method * runs no URLPattern match while Vue Router answers for that route. * * **The constraint:** the params of Vue Router name the params of the route of * VUE-ROUTER, and not the params of the route of the MACHINE. The Play architecture * wants a passive router: the actor owns the routing, and the host app registers * one catch-all route (`/:pathMatch(.*)*`), as `examples/demo/src/router.ts` does. The params of Vue Router then hold * the splat alone, and they can hold a name of the route map, such as `userId`, * never. * * The method therefore reads the pattern of the route map first, and * {@link resolveFrameworkParams} decides on the names that the pattern declares. The * branches live there, because `SolidRouterBridge` holds the same ones, and the * source of the params is the one difference between the two bridges. * * Two of those branches reach the URLPattern extraction of the base class: a bridge * under a `basePath`, where Vue Router matched a route of the HOST, and a route where * Vue Router reports none of the REQUIRED names of the pattern. * * A location that fills NO optional segment of an all-optional pattern reaches * neither: `/settings` is the bare form of `/settings/:section?`, so the params are * `{}` and the path alone says so. * * The API itself is always present. `@xmachines/play-url` carries * `urlpattern-polyfill` as an ordinary dependency and it uses the native URLPattern * when the runtime has one, so what these branches decide is the COST of a navigation * and never its availability. A BAD pattern is a question of the ROUTE MAP: it * compiles each parameterized route in its constructor and throws an * `InvalidRoutePatternError` there, whatever this method decides. * * @param pathname - The URL path, for the URLPattern fallback * @param stateId - The matched state ID, for the lookup of the route pattern */ protected extractParams(pathname: string, stateId: string): Record; /** * Subscribes to the Vue Router changes with the `watch` function of `@vue/reactivity`. * * `router.currentRoute` is a Vue `ShallowRef`. Vue * updates it one time for each navigation, and only on a real change of the route. * The watcher therefore fires exactly one time. `afterEach` is different: it also * fires for a push from the actor to the router that lands on the same URL. The * watcher removes that GAP-12 double fire. * * The callback calls `syncActorFromRouter` of the base class. That method cleans * the path, suppresses an echo, guards against re-entrance, AND keeps the contract * for a path without a match: a navigation to a path with no route pushes the * current route of the actor back to the router, so the URL and the actor state * never separate. The bridge still uses the params and the query that Vue parsed: * the params through the `extractParams` override, and the query through * `searchFromQuery(to.query)`. * * A `RouterSyncError` of the base synchronization becomes a * {@link VueRouterSendError}, which keeps the error surface of this package. Every * other error, such as an `InvalidRoutePatternError`, goes to the caller without * a change. * * The `watch` function comes from `@vue/reactivity`, not from `vue` or * `@vue/runtime-core`. An error from the callback therefore goes through the * `endBatch` path of the reactivity scheduler (`if (error) throw error`). It does * not go through `callWithErrorHandling`, which sends the error to the global error * handler of Vue and writes a false warning: "Unhandled error during execution of * watcher callback". The option `flush: "sync"` runs the callback in the same * synchronous frame as the change of the ref. */ protected watchRouterChanges(): void; protected unwatchRouterChanges(): void; protected getInitialRouterPath(): string | null; /** * Returns the initial URL search string, so that `connect()` can forward the query params. * * The method builds the string from the `route.query` object of vue-router, with * the same `searchFromQuery` function as the watcher. It does NOT slice `fullPath`, * because the hash fragment of `fullPath` leaks into a query value. It returns * `undefined` when no query param is present. `syncActorFromRouter` then makes * `query: {}`, and it does not parse an empty string. */ protected getInitialRouterSearch(): string | undefined; } //# sourceMappingURL=vue-router-bridge.d.ts.map