Skip to content

Functions: createRouter() ​

Call Signature ​

ts
function createRouter<TRoutes, TOptions, TPlugin>(
   routes, 
   options?, 
   plugins?
): Router<TRoutes, TOptions, TPlugin>;

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

Type Parameters ​

Type ParameterDefault type
TRoutes extends Routes-
TOptions extends RouterOptionsobject
TPlugin extends RouterPluginEmptyRouterPlugin

Parameters ​

ParameterTypeDescription
routesTRoutesRoutes An array of route definitions specifying the configuration of routes in the application. Use createRoute method to create the route definitions.
options?TOptionsRouterOptions for the router, including history mode and initial URL settings.
plugins?TPlugin[]-

Returns ​

Router<TRoutes, TOptions, TPlugin>

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 }),
] as const

const router = createRouter(routes)

Call Signature ​

ts
function createRouter<TRoutes, TOptions, TPlugin>(
   routes, 
   options?, 
   plugins?
): Router<TRoutes, TOptions, TPlugin>;

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

Type Parameters ​

Type ParameterDefault type
TRoutes extends Routes-
TOptions extends RouterOptionsobject
TPlugin extends RouterPluginEmptyRouterPlugin

Parameters ​

ParameterTypeDescription
routesTRoutes[]Routes An array of route definitions specifying the configuration of routes in the application. Use createRoute method to create the route definitions.
options?TOptionsRouterOptions for the router, including history mode and initial URL settings.
plugins?TPlugin[]-

Returns ​

Router<TRoutes, TOptions, TPlugin>

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 }),
] as const

const router = createRouter(routes)