You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/api/README.md
+37-7Lines changed: 37 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -13,22 +13,52 @@ sidebar: auto
13
13
`<router-link>` is preferred over hard-coded `<a href="...">` for the following reasons:
14
14
15
15
- It works the same way in both HTML5 history mode and hash mode, so if you ever decide to switch mode, or when the router falls back to hash mode in IE9, nothing needs to be changed.
16
-
17
16
- In HTML5 history mode, `router-link` will intercept the click event so that the browser doesn't try to reload the page.
18
-
19
17
- When you are using the `base` option in HTML5 history mode, you don't need to include it in `to` prop's URLs.
20
18
21
-
### Applying Active Class to Outer Element
19
+
### `v-slot` API (+3.1.0)
20
+
21
+
`router-link` exposes a low level customization through a [scoped slot](https://vuejs.org/v2/guide/components-slots.html#Scoped-Slots). This is a more advanced API that primarily targets library authors but can come in handy for developers as well, most of the time in a custom component like a _NavLink_ or other.
22
+
23
+
**When using the `v-slot` API, it is required to pass one single child to `router-link`**. If you don't, `router-link` will wrap its children in a `span` element.
-`href`: resolved url. This would be the `href` attribute of an `a` element
37
+
-`route`: resolved normalized location
38
+
-`navigate`: function to trigger the navigation. **It will automatically prevent events when necessary**, the same way `router-link` does
39
+
-`isActive`: `true` if the [active class](#active-class) should be applied. Allows to apply an arbitrary class
40
+
-`isExactActive`: `true` if the [exact active class](#exact-active-class) should be applied. Allows to apply an arbitrary class
41
+
42
+
#### Example: Applying Active Class to Outer Element
22
43
23
-
Sometimes we may want the active class to be applied to an outer element rather than the `<a>` tag itself, in that case, you can render that outer element using `<router-link>` and wrap the raw `<a>` tag inside:
44
+
Sometimes we may want the active class to be applied to an outer element rather than the `<a>` tag itself, in that case, you can wrap that element inside a `router-link` and use the `v-slot` properties to create your link:
0 commit comments