Skip to content

Latest commit

 

History

History
208 lines (126 loc) · 4.05 KB

RouterOptions.md

File metadata and controls

208 lines (126 loc) · 4.05 KB
editLink

API Documentation / RouterOptions

Interface: RouterOptions

Options to initialize a Router instance.

Hierarchy

Properties

end

Optional end: boolean

Should the RegExp match until the end by appending a $ to it.

Default Value

true

Inherited from

PathParserOptions.end


history

history: RouterHistory

History implementation used by the router. Most web applications should use createWebHistory but it requires the server to be properly configured. You can also use a hash based history with createWebHashHistory that does not require any configuration on the server but isn't handled at all by search engines and does poorly on SEO.

Example

createRouter({
  history: createWebHistory(),
  // other options...
})

linkActiveClass

Optional linkActiveClass: string

Default class applied to active RouterLink. If none is provided, router-link-active will be applied.


linkExactActiveClass

Optional linkExactActiveClass: string

Default class applied to exact active RouterLink. If none is provided, router-link-exact-active will be applied.


parseQuery

Optional parseQuery: (search: string) => LocationQuery

Custom implementation to parse a query. See its counterpart, RouterOptions.stringifyQuery.

Example

Let's say you want to use the qs package to parse queries, you can provide both parseQuery and stringifyQuery:

import qs from 'qs'

createRouter({
  // other options...
  parseQuery: qs.parse,
  stringifyQuery: qs.stringify,
})

Type declaration

▸ (search): LocationQuery

Custom implementation to parse a query. See its counterpart, RouterOptions.stringifyQuery.

Parameters
Name Type
search string
Returns

LocationQuery

Example

Let's say you want to use the qs package to parse queries, you can provide both parseQuery and stringifyQuery:

import qs from 'qs'

createRouter({
  // other options...
  parseQuery: qs.parse,
  stringifyQuery: qs.stringify,
})

routes

routes: readonly RouteRecordRaw[]

Initial list of routes that should be added to the router.


scrollBehavior

Optional scrollBehavior: RouterScrollBehavior

Function to control scrolling when navigating between pages. Can return a Promise to delay scrolling. Check ScrollBehavior.

Example

function scrollBehavior(to, from, savedPosition) {
  // `to` and `from` are both route locations
  // `savedPosition` can be null if there isn't one
}

sensitive

Optional sensitive: boolean

Makes the RegExp case-sensitive.

Default Value

false

Inherited from

PathParserOptions.sensitive


strict

Optional strict: boolean

Whether to disallow a trailing slash or not.

Default Value

false

Inherited from

PathParserOptions.strict


stringifyQuery

Optional stringifyQuery: (query: LocationQueryRaw) => string

Custom implementation to stringify a query object. Should not prepend a leading ?. parseQuery counterpart to handle query parsing.

Type declaration

▸ (query): string

Custom implementation to stringify a query object. Should not prepend a leading ?. parseQuery counterpart to handle query parsing.

Parameters
Name Type
query LocationQueryRaw
Returns

string