Vue Router integration for @ionic/vue with Ionic-specific navigation features
npx @tessl/cli install tessl/npm-ionic--vue-router@8.7.0@ionic/vue-router is a Vue Router integration library specifically designed for Ionic Vue applications. It extends standard Vue Router functionality with Ionic-specific navigation features including view stack management, tab navigation support, and mobile-optimized routing behaviors.
npm install @ionic/vue-routerimport { createRouter, createWebHistory, createWebHashHistory, createMemoryHistory } from "@ionic/vue-router";For TypeScript types (not available as main exports, access through internal paths if needed):
import type { IonicVueRouterOptions, RouteInfo, RouteAction, RouteDirection } from "@ionic/vue-router/dist/types/types";For CommonJS:
const { createRouter, createWebHistory, createWebHashHistory, createMemoryHistory } = require("@ionic/vue-router");import { createApp, inject } from 'vue';
import { createRouter, createWebHistory } from "@ionic/vue-router";
import App from './App.vue';
// Define routes
const routes = [
{ path: '/', component: () => import('./views/Home.vue') },
{ path: '/about', component: () => import('./views/About.vue') },
];
// Create router with Ionic features
const router = createRouter({
history: createWebHistory(),
routes,
tabsPrefix: '/tabs/' // Optional: prefix for tab-based routes
});
// Create and mount app
const app = createApp(App);
app.use(router);
app.mount('#app');
// Access providers in components
export default {
setup() {
const navManager = inject('navManager'); // Navigation management
const viewStacks = inject('viewStacks'); // View stack management
return { navManager, viewStacks };
}
};@ionic/vue-router is built around several key components:
createRouter function that wraps Vue Router with Ionic-specific capabilitiesThe router enhances Vue Router by providing two key injected providers:
navManager: Programmatic navigation with Ionic-specific featuresviewStacks: Advanced view stack management for complex navigation scenariosCore router factory function and history utilities that create an enhanced Vue Router instance with Ionic navigation capabilities.
function createRouter(opts: IonicVueRouterOptions): Router;
interface IonicVueRouterOptions extends RouterOptions {
tabsPrefix?: string;
}Programmatic navigation APIs with Ionic-specific features like animations, directions, and tab handling.
// Navigation methods available through injected navManager
interface NavigationManager {
handleNavigate(
path: RouteLocationRaw,
routerAction?: RouteAction,
routerDirection?: RouteDirection,
routerAnimation?: AnimationBuilder,
tab?: string
): void;
handleNavigateBack(defaultHref?: string, routerAnimation?: AnimationBuilder): void;
getCurrentRouteInfo(): RouteInfo;
canGoBack(deep?: boolean): boolean;
navigate(navigationOptions: ExternalNavigationOptions): void;
}Advanced view stack management system for handling complex navigation scenarios including multi-outlet routing, view lifecycle management, and component state preservation.
// View stack methods available through injected viewStacks provider
interface ViewStacksManager {
size(): number;
getViewStack(outletId: number): ViewItem[] | undefined;
createViewItem(
outletId: number,
vueComponent: any,
matchedRoute: RouteLocationMatched,
routeInfo: RouteInfo,
ionPage?: HTMLElement
): ViewItem;
findViewItemByRouteInfo(routeInfo: RouteInfo, outletId?: number): ViewItem | undefined;
getChildrenToRender(outletId: number): ViewItem[];
}Complete TypeScript type definitions for all router functionality including route information, navigation parameters, and view management.
interface RouteInfo {
id?: string;
routerAction?: RouteAction;
routerDirection?: RouteDirection;
routerAnimation?: AnimationBuilder;
pathname?: string;
search?: string;
params?: { [k: string]: any };
tab?: string;
}
type RouteAction = "push" | "pop" | "replace";
type RouteDirection = "forward" | "back" | "root" | "none";