From: cnschwarz Date: Wed, 9 Feb 2022 07:59:12 +0000 (+0100) Subject: docs: document strict and sensitive option (#1294) X-Git-Tag: v4.0.13~19 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=54e4f01498fce6dc353d8e7b94bb5c24c540ad4c;p=thirdparty%2Fvuejs%2Frouter.git docs: document strict and sensitive option (#1294) Co-authored-by: Eduardo San Martin Morote --- diff --git a/docs/api/index.md b/docs/api/index.md index e95b80e4..72db6f23 100644 --- a/docs/api/index.md +++ b/docs/api/index.md @@ -848,6 +848,18 @@ Route record that can be provided by the user when adding routes via the [`route - **See Also**: [Passing props to Route Components](../guide/essentials/passing-props.md) +### sensitive +- **Type**: `boolean` (Optional) +- **Details**: + + Makes the route matching case sensitive, defaults to `false`. Note this can also be set at a route level. + +### strict +- **Type**: `boolean` (Optional) +- **Details**: + + Strictly checks the presence or absence of a trailing slash (`/`) at the end of the path. Defaults to `false` meaning that by default a route `/users` matches both `/users` and `/users/`. Note this can also be set at a route level. + ### meta - **Type**: [`RouteMeta`](#routemeta) (Optional) diff --git a/docs/guide/essentials/route-matching-syntax.md b/docs/guide/essentials/route-matching-syntax.md index 5210df3d..9f7d3e98 100644 --- a/docs/guide/essentials/route-matching-syntax.md +++ b/docs/guide/essentials/route-matching-syntax.md @@ -75,6 +75,25 @@ const routes = [ ] ``` +## Sensitive and strict route options + +By default, all routes are case-insensitive and match routes with or without a trailing slash. e.g. a route `/users` matches `/users`, `/users/`, and even `/Users/`. This behavior can be configured with the `strict` and `sensitive` options, they can be set both at a router and route level: + +```js +const router = createRouter({ + history: createWebHistory(), + routes: [ + // will match /users/posva but not: + // - /users/posva/ because of strict: true + // - /Users/posva because of sensitive: true + { path: '/users/:id', sensitive: true }, + // will match /users, /Users, and /users/42 but not /users/ or /users/42/ + { path: '/users/:id?' }, + ] + strict: true, // applies to all routes +}) +``` + ## Optional parameters You can also mark a parameter as optional by using the `?` modifier (0 or 1):