From 7329900ae549430b88567a09cbb585d3cf0a6d32 Mon Sep 17 00:00:00 2001 From: Sandro Circi Date: Sun, 17 Nov 2024 12:16:19 +0100 Subject: [PATCH] feat(Link): allow partial query match for its active state (#2664) Co-authored-by: Benjamin Canac --- docs/content/3.components/link.md | 1 + src/runtime/components/Link.vue | 23 ++++++++++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/docs/content/3.components/link.md b/docs/content/3.components/link.md index 49549ba1..28243663 100644 --- a/docs/content/3.components/link.md +++ b/docs/content/3.components/link.md @@ -13,6 +13,7 @@ The Link component is a wrapper around [``](https://nuxt.com/docs/api/ - `inactive-class` prop to set a class when the link is inactive, `active-class` is used when active. - `exact` prop to style with `active-class` when the link is active and the route is exactly the same as the current route. - `exact-query` and `exact-hash` props to style with `active-class` when the link is active and the query or hash is exactly the same as the current query or hash. + - use `exact-query="partial"` to style with `active-class` when the link is active and the query partially match the current query. The incentive behind this is to provide the same API as NuxtLink back in Nuxt 2 / Vue 2. You can read more about it in the Vue Router [migration from Vue 2](https://router.vuejs.org/guide/migration/#removal-of-the-exact-prop-in-router-link) guide. diff --git a/src/runtime/components/Link.vue b/src/runtime/components/Link.vue index 7dbfa682..4f16714d 100644 --- a/src/runtime/components/Link.vue +++ b/src/runtime/components/Link.vue @@ -73,8 +73,8 @@ export interface LinkProps extends NuxtLinkProps { active?: boolean /** Will only be active if the current route is an exact match. */ exact?: boolean - /** Will only be active if the current route query is an exact match. */ - exactQuery?: boolean + /** Allows controlling how the current route query sets the link as active. */ + exactQuery?: boolean | 'partial' /** Will only be active if the current route hash is an exact match. */ exactHash?: boolean /** The class to apply when the link is inactive. */ @@ -94,7 +94,7 @@ extendDevtoolsMeta({ example: 'LinkExample' })