Routing
VableAI can navigate your Vue app on the user's behalf. You tell the SDK which routes exist — the AI agent handles the rest when the user says something like "take me to my account" or "open settings".
Overview
Setup has two steps:
- Pass your routes to the
Vablecomponent via theroutesprop - Use
VableNavigationas the root route component so Vable can intercept navigation events
Setting up VableNavigation
VableNavigation wraps Vue Router's <router-view> and listens for navigation events from the AI agent. It must be the component of your root/layout route.
import { VableNavigation } from "@vableai/vue";
const routes = [
{
path: "/",
component: VableNavigation,
children: [
{ path: "", component: () => import("./pages/Home.vue") },
{ path: "account", component: () => import("./pages/Account.vue") },
{ path: "settings", component: () => import("./pages/Settings.vue") },
],
},
];
Then pass the routes to the Vable component:
<template>
<Vable public-key="<replace_with_public_key>" :routes="routes">
<RouterView />
</Vable>
</template>
<script setup>
import { Vable } from "@vableai/vue/init";
import { routes } from "./router";
</script>
VableNavigation renders a Vue Router <router-view> internally. It replaces wherever you would normally put <RouterView /> in your layout route.
How it works
When the AI agent determines the user wants to navigate:
- The vable-chat widget dispatches a
vableNavigationEventwith the target URL VableNavigationreceives the event and validates the URL against your declared routes- If the route exists, it calls
router.push(url)via Vue Router - If the URL points to a different hostname, it opens the link in the current tab
Route validation
VableNavigation only navigates to routes that exist in your route configuration. If the AI suggests a route that doesn't match any declared path, the navigation is ignored and an error is logged.
This prevents the AI from navigating to arbitrary URLs within your app.
External URLs
If the AI agent provides a full URL with a different hostname (e.g. a documentation link or external resource), VableNavigation opens it in the current tab using window.open instead of using Vue Router.
Full Example
// router.ts
import { createRouter, createWebHistory } from "vue-router";
import { VableNavigation } from "@vableai/vue";
export const routes = [
{
path: "/",
component: VableNavigation,
children: [
{ path: "", component: () => import("./pages/Home.vue") },
{ path: "account", component: () => import("./pages/Account.vue") },
{ path: "settings", component: () => import("./pages/Settings.vue") },
],
},
];
export const router = createRouter({
history: createWebHistory(),
routes,
});
<!-- App.vue -->
<template>
<Vable public-key="<replace_with_public_key>" :routes="routes">
<RouterView />
</Vable>
</template>
<script setup>
import { Vable } from "@vableai/vue/init";
import { routes } from "./router";
</script>