Skip to content

vue-router / RouterOptions

RouterOptions

Options to initialize a Router instance.

Extends

  • EXPERIMENTAL_RouterOptions_Base

Properties

end?

ts
optional end: boolean;

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

Default Value

true

Inherited from

ts
EXPERIMENTAL_RouterOptions_Base.end

history

ts
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

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

Inherited from

ts
EXPERIMENTAL_RouterOptions_Base.history

linkActiveClass?

ts
optional linkActiveClass: string;

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

Inherited from

ts
EXPERIMENTAL_RouterOptions_Base.linkActiveClass

linkExactActiveClass?

ts
optional linkExactActiveClass: string;

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

Inherited from

ts
EXPERIMENTAL_RouterOptions_Base.linkExactActiveClass

parseQuery()?

ts
optional parseQuery: (search) => LocationQuery;

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

Internal

Transforms a queryString into a LocationQuery object. Accept both, a version with the leading ? and without Should work as URLSearchParams

Parameters

string

search string to parse

Returns

LocationQuery

a query object

Example

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

js
import qs from 'qs'

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

Inherited from

ts
EXPERIMENTAL_RouterOptions_Base.parseQuery

routes

ts
routes: readonly RouteRecordRaw[];

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


scrollBehavior?

ts
optional scrollBehavior: RouterScrollBehavior;

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

See

RouterScrollBehavior.

Example

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

Inherited from

ts
EXPERIMENTAL_RouterOptions_Base.scrollBehavior

sensitive?

ts
optional sensitive: boolean;

Makes the RegExp case-sensitive.

Default Value

false

Inherited from

ts
EXPERIMENTAL_RouterOptions_Base.sensitive

strict?

ts
optional strict: boolean;

Whether to disallow a trailing slash or not.

Default Value

false

Inherited from

ts
EXPERIMENTAL_RouterOptions_Base.strict

stringifyQuery()?

ts
optional stringifyQuery: (query) => string;

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

Internal

Stringifies a LocationQueryRaw object. Like URLSearchParams, it doesn't prepend a ?

Parameters

query

query object to stringify

undefined | LocationQueryRaw

Returns

string

string version of the query without the leading ?

Inherited from

ts
EXPERIMENTAL_RouterOptions_Base.stringifyQuery

Released under the MIT License.