strict

Customise Route location arguments strictness for NuxtLink or router.

  • All strict options are disabled by default.
  • You can tweak options to add strict router navigation options.

Type

/**
 * @default false
 */
strict?: boolean | StrictOptions;

Exemple config

nuxt.config.ts
export default defineNuxtConfig({
  ...,
  nuxtTypedRouter: {
    strict: true,
    // or
    strict: {
      router: {
        strictToArgument: true
      }
    }
  }
})

StrictOptions properties

export interface StrictOptions {
  NuxtLink?: StrictParamsOptions;
  router?: StrictParamsOptions;
}
export interface StrictParamsOptions {
  /**
   * @default false
   */
  strictToArgument?: boolean;
  /**
   * @default false
   */
  strictRouteLocation?: boolean;
}

strictToArgument

Prevent passing string path to the RouteLocation argument.

Ex:

<template>
  <NuxtLink to='/login'/> // Error ❌
</template>

Or

router.push('/login'); // Error ❌
navigateTo('/login'); // Error ❌

strictRouteLocation

Prevent passing a params property in the RouteLocation argument.

Ex:

<template>
  <NuxtLink :to='{path: "/login"}'/> // Error ❌
</template>

Or

router.push({path: "/login"}); // Error ❌
navigateTo({path: "/login"}); // Error ❌