]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
docs: document strict and sensitive option (#1294)
authorcnschwarz <cnschwarz@users.noreply.github.com>
Wed, 9 Feb 2022 07:59:12 +0000 (08:59 +0100)
committerGitHub <noreply@github.com>
Wed, 9 Feb 2022 07:59:12 +0000 (08:59 +0100)
Co-authored-by: Eduardo San Martin Morote <posva@users.noreply.github.com>
docs/api/index.md
docs/guide/essentials/route-matching-syntax.md

index e95b80e41ca53b76c072221a7e7d16ef828af290..72db6f23ea5071675b260a7324f24f967e5473c9 100644 (file)
@@ -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)
index 5210df3d7bd849fda8a8151c9c7f41a45f886d87..9f7d3e9882d677c47fecd2a6a0a27971c2c8c51b 100644 (file)
@@ -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):