Nuxt/packages/schema/src/config/router.ts

172 lines
5.2 KiB
TypeScript
Raw Normal View History

import { normalizeURL, withTrailingSlash } from 'ufo'
export default {
/**
* Additional options passed to `vue-router`.
*
* Note: Only JSON serializable options should be passed by nuxt config.
*
* For more control, you can use `app/router.optionts.ts` file.
*
* @see [documentation](https://router.vuejs.org/api/interfaces/routeroptions.html).
* @type {import('../src/types/router').RouterConfigSerializable}
*
* @version 3
*/
options: {},
2021-04-15 18:49:29 +00:00
/**
* Configure the router mode.
*
* For server-side rendering it is not recommended to change it.
* @version 2
2021-04-15 18:49:29 +00:00
*/
mode: 'history',
2021-04-15 18:49:29 +00:00
/**
* The base URL of the app. For example, if the entire single page application is
* served under `/app/`, then base should use the value `'/app/'`.
2021-04-15 18:49:29 +00:00
*
* This can be useful if you need to serve Nuxt as a different context root, from
* within a bigger web site.
* @version 2
2021-04-15 18:49:29 +00:00
*/
base: {
$resolve: (val, get) => val ? withTrailingSlash(normalizeURL(val)) : get('app').baseURL
},
2021-04-15 18:49:29 +00:00
/** @private */
_routerBaseSpecified: {
$resolve: (_val, get) => typeof get('router.base') === 'string'
},
2021-04-15 18:49:29 +00:00
/** @version 2 */
routes: [],
2021-04-15 18:49:29 +00:00
/**
* This allows changing the separator between route names that Nuxt uses.
*
* Imagine we have the page file `pages/posts/_id.vue`. Nuxt will generate the
* route name programmatically, in this case `posts-id`. If you change the routeNameSplitter
* config to `/` the name will change to `posts/id`.
* @version 2
2021-04-15 18:49:29 +00:00
*/
routeNameSplitter: '-',
2021-04-15 18:49:29 +00:00
/**
* Set the default(s) middleware for every page of the application.
* @version 2
2021-04-15 18:49:29 +00:00
*/
middleware: {
$resolve: val => Array.isArray(val) ? val : [val].filter(Boolean)
},
2021-04-15 18:49:29 +00:00
/**
* Globally configure `<nuxt-link>` default active class.
* @version 2
2021-04-15 18:49:29 +00:00
*/
linkActiveClass: 'nuxt-link-active',
2021-04-15 18:49:29 +00:00
/**
* Globally configure `<nuxt-link>` default exact active class.
* @version 2
2021-04-15 18:49:29 +00:00
*/
linkExactActiveClass: 'nuxt-link-exact-active',
2021-04-15 18:49:29 +00:00
/**
* Globally configure `<nuxt-link>` default prefetch class (feature disabled by default).
* @version 2
2021-04-15 18:49:29 +00:00
*/
linkPrefetchedClass: false,
2021-04-15 18:49:29 +00:00
/**
* You can pass a function to extend the routes created by Nuxt.
*
* @example
* ```js
* import { fileURLToPath } from 'url'
* export default {
* router: {
* extendRoutes(routes, resolve) {
* routes.push({
* name: 'custom',
* path: '*',
* component: fileURLToPath(new URL('./pages/404.vue', import.meta.url))
* })
* }
* }
* }
2021-04-15 18:49:29 +00:00
* ```
* @version 2
2021-04-15 18:49:29 +00:00
*/
extendRoutes: null,
2021-04-15 18:49:29 +00:00
/**
* The `scrollBehavior` option lets you define a custom behavior for the scroll
* position between the routes. This method is called every time a page is
* rendered. To learn more about it, see the `vue-router` documentation.
2021-04-15 18:49:29 +00:00
*
* @see [vue-router `scrollBehavior` documentation](https://router.vuejs.org/guide/advanced/scroll-behavior.html).
* @version 2
2021-04-15 18:49:29 +00:00
*/
scrollBehavior: {
$schema: {
deprecated: 'router.scrollBehavior` property is deprecated in favor of using `~/app/router.scrollBehavior.js` file, learn more: https://nuxtjs.org/api/configuration-router#scrollbehavior'
}
},
2021-04-15 18:49:29 +00:00
/**
* Provide custom query string parse function. Overrides the default.
* @version 2
2021-04-15 18:49:29 +00:00
*/
parseQuery: false,
2021-04-15 18:49:29 +00:00
/**
* Provide custom query string stringify function. Overrides the default.
* @version 2
2021-04-15 18:49:29 +00:00
*/
stringifyQuery: false,
2021-04-15 18:49:29 +00:00
/**
* Controls whether the router should fall back to hash mode when the browser
* does not support history.pushState, but mode is set to history.
2021-04-15 18:49:29 +00:00
*
* Setting this to `false` essentially makes every router-link navigation a full
2021-04-15 18:49:29 +00:00
* page refresh in IE9. This is useful when the app is server-rendered and needs
* to work in IE9, because a hash mode URL does not work with SSR.
* @version 2
2021-04-15 18:49:29 +00:00
*/
fallback: false,
2021-04-15 18:49:29 +00:00
/**
* Configure `<nuxt-link>` to prefetch the code-splitted page when detected within
* the viewport. Requires [IntersectionObserver](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API) to be supported (see [Caniuse](https://caniuse.com/intersectionobserver)).
* @version 2
2021-04-15 18:49:29 +00:00
*/
prefetchLinks: true,
2021-04-15 18:49:29 +00:00
/**
* When using `nuxt generate` with target: 'static', Nuxt will generate a
2021-04-15 18:49:29 +00:00
* payload.js for each page.
*
* With this option enabled, Nuxt will automatically prefetch the payload of the
* linked page when the `<nuxt-link>` is visible in the viewport, making instant navigation.
* @version 2
2021-04-15 18:49:29 +00:00
*/
prefetchPayloads: true,
2021-04-15 18:49:29 +00:00
/**
* If this option is set to `true`, trailing slashes will be appended to every
* route. If set to `false`, they'll be removed.
2021-04-15 18:49:29 +00:00
*
* @warning This option should not be set without preparation and has to
2021-04-15 18:49:29 +00:00
* be tested thoroughly. When setting `trailingSlash` to something else than
* `undefined`, the opposite route will stop working. Thus, 301 redirects should
2021-04-15 18:49:29 +00:00
* be in place and your internal linking has to be adapted correctly. If you set
* `trailingSlash` to `true`, then only `example.com/abc/` will work, but not
* `example.com/abc`. On `false`, it's vice-versa.
* @version 2
2021-04-15 18:49:29 +00:00
*/
trailingSlash: undefined
}