]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
docs: explain per-route guards on nested routes (#2130)
authorskirtle <65301168+skirtles-code@users.noreply.github.com>
Tue, 6 Feb 2024 08:13:39 +0000 (08:13 +0000)
committerGitHub <noreply@github.com>
Tue, 6 Feb 2024 08:13:39 +0000 (09:13 +0100)
packages/docs/guide/advanced/navigation-guards.md
packages/docs/guide/essentials/nested-routes.md

index 1d0067f60393bb35ecfd6362f01e6deeb11fab8a..57884d3c7eeaab19848c99d66fabab552509baee 100644 (file)
@@ -197,7 +197,28 @@ const routes = [
 ]
 ```
 
-Note it is possible to achieve a similar behavior by using [route meta fields](./meta.md) and global navigation guards.
+When working with [nested routes](../essentials/nested-routes), both parent and child routes can use `beforeEnter`. When placed on a parent route, it won't be triggered when moving between children with that same parent. For example:
+
+```js
+const routes = [
+  {
+    path: '/user',
+    beforeEnter() {
+      // ...
+    },
+    children: [
+      { path: 'list', component: UserList },
+      { path: 'details', component: UserDetails },
+    ],
+  },
+]
+```
+
+The `beforeEnter` in the example above won't be called when moving between `/user/list` and `/user/details`, as they share the same parent. If we put the `beforeEnter` guard directly on the `details` route instead, that would be called when moving between those two routes.
+
+::: tip
+It is possible to achieve similar behavior to per-route guards by using [route meta fields](./meta) and global navigation guards.
+:::
 
 ## In-Component Guards
 
index c48241332ddf71d1d3835dc2d4bd8420093833b0..fd3764b1cf9458c6f95b934fda2c7db30da95015 100644 (file)
@@ -131,7 +131,7 @@ const routes = [
 
 ## Omitting parent components <Badge text="4.1+" />
 
-We can also take advantage of the parent-child relationship between routes without needing to nest route components. This can be useful for grouping together routes with a common path prefix, or when working with [route meta fields](../advanced/meta).
+We can also take advantage of the parent-child relationship between routes without needing to nest route components. This can be useful for grouping together routes with a common path prefix, or when working with more advanced features, such as [per-route navigation guards](../advanced/navigation-guards#Per-Route-Guard) or [route meta fields](../advanced/meta).
 
 To achieve this, we omit the `component` and `components` options from the parent route: