Skip to content

createRouter

ts
function createRouter<T>(routes, options?): Router<T>

Creates a router instance for a Vue application, equipped with methods for route handling, lifecycle hooks, and state management.

Type parameters

Type parameter
T extends readonly Route[]

Parameters

ParameterTypeDescription
routesTRoutes An array of route definitions specifying the configuration of routes in the application. Use createRoute or createExternalRoute method to create the route definitions.
options?RouterOptionsRouterOptions for the router, including history mode and initial URL settings.

Returns

Router<T>

Router instance

Example

ts
import { createRoute, createRouter } from '@kitbag/router'

const Home = { template: '<div>Home</div>' }
const About = { template: '<div>About</div>' }

export const routes = [
  createRoute({ name: 'home', path: '/', component: Home }),
  createRoute({ name: 'path', path: '/about', component: About }),
]

const router = createRouter(routes)