-
Notifications
You must be signed in to change notification settings - Fork 288
Updating <router-link> to no longer use the deprecated :tag property #10793
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,65 +28,10 @@ export default { | |
}, | ||
|
||
data() { | ||
return { | ||
near: false, | ||
over: false, | ||
menuPath: this.type.route ? this.$router.resolve(this.type.route)?.route?.path : undefined, | ||
Comment on lines
-33
to
-34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These weren't used. |
||
}; | ||
return { near: false }; | ||
}, | ||
|
||
computed: { | ||
isCurrent() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This wasn't used in the file. |
||
// This is required to avoid scenarios where fragments break vue routers location matching | ||
// For example, the following fails | ||
// Curruent Path /c/c-m-hzqf4tqt/explorer/members#project-membership | ||
// Menu Path /c/c-m-hzqf4tqt/explorer/members | ||
// vue-router exact-path="true" fixes this (https://v3.router.vuejs.org/api/#exact-path), | ||
// but fails when the the current path is a child (for instance a resource detail page) | ||
|
||
// Scenarios to consider | ||
// - Fragement world | ||
// Curruent Path /c/c-m-hzqf4tqt/explorer/members#project-membership | ||
// Menu Path /c/c-m-hzqf4tqt/explorer/members | ||
// - Similar current paths | ||
// /c/c-m-hzqf4tqt/fleet/fleet.cattle.io.bundlenamespacemapping | ||
// /c/c-m-hzqf4tqt/fleet/fleet.cattle.io.bundle | ||
// - Other menu items that appear in current menu item | ||
// /c/c-m-hzqf4tqt/fleet | ||
// /c/c-m-hzqf4tqt/fleet/management.cattle.io.fleetworkspace | ||
|
||
// If there's no hash the n-link will determine it's linkActiveClass correctly, so avoid this faff | ||
const invalidHash = !this.$route.hash; | ||
// Lets be super safe | ||
const invalidProps = !this.menuPath || !this.$route.path; | ||
|
||
if (invalidHash || invalidProps) { | ||
return false; | ||
} | ||
|
||
// We're kind of, but in a fixing way, copying n-link --> vue-router link see vue-router/src/components/link.js & vue-router/src/util/route.js | ||
// We're only going to compare the path and ignore query and fragment | ||
|
||
if (this.type.exact) { | ||
return this.$route.path === this.menuPath; | ||
} | ||
|
||
const currentPath = this.$route.path.split('/'); | ||
const menuPath = this.menuPath.split('/'); | ||
|
||
if (menuPath.length > currentPath.length) { | ||
return false; | ||
} | ||
|
||
for (let i = 0; i < menuPath.length; i++) { | ||
if (menuPath[i] !== currentPath[i]) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
}, | ||
|
||
showFavorite() { | ||
return ( this.type.mode && this.near && showFavoritesFor.includes(this.type.mode) ); | ||
}, | ||
|
@@ -116,14 +61,6 @@ export default { | |
this.near = val; | ||
}, | ||
|
||
setOver(val) { | ||
this.over = val; | ||
}, | ||
|
||
removeFavorite() { | ||
this.$store.dispatch('type-map/removeFavorite', this.type.name); | ||
}, | ||
Comment on lines
-119
to
-125
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unused |
||
|
||
selectType() { | ||
// Prevent issues if custom NavLink is used #5047 | ||
if (this.type?.route) { | ||
|
@@ -142,63 +79,70 @@ export default { | |
<router-link | ||
v-if="type.route" | ||
:key="type.name" | ||
v-slot="{ href, navigate, isActive, isExactActive }" | ||
custom | ||
:to="type.route" | ||
tag="li" | ||
class="child nav-type" | ||
:class="{'root': isRoot, [`depth-${depth}`]: true, 'router-link-active': isCurrent}" | ||
:exact="type.exact" | ||
> | ||
<TabTitle | ||
v-if="$router.resolve(type.route).route.path === $route.path" | ||
:show-child="false" | ||
> | ||
{{ type.labelKey ? t(type.labelKey) : (type.labelDisplay || type.label) }} | ||
</TabTitle> | ||
<a | ||
@click="selectType" | ||
@mouseenter="setNear(true)" | ||
@mouseleave="setNear(false)" | ||
<li | ||
class="child nav-type" | ||
:class="{'root': isRoot, [`depth-${depth}`]: true, 'router-link-active': isActive, 'router-link-exact-active': isExactActive}" | ||
@click="navigate" | ||
@keypress.enter="navigate" | ||
> | ||
<span | ||
v-if="type.labelKey" | ||
class="label" | ||
><t :k="type.labelKey" /></span> | ||
<span | ||
v-else | ||
v-clean-html="type.labelDisplay || type.label" | ||
class="label" | ||
:class="{'no-icon': !type.icon}" | ||
/> | ||
<span | ||
v-if="showFavorite || namespaceIcon || showCount" | ||
class="count" | ||
<TabTitle | ||
v-if="isExactActive" | ||
:show-child="false" | ||
> | ||
<Favorite | ||
v-if="showFavorite" | ||
:resource="type.name" | ||
/> | ||
<i | ||
v-if="namespaceIcon" | ||
class="icon icon-namespace" | ||
:class="{'ns-and-icon': showCount}" | ||
{{ type.labelKey ? t(type.labelKey) : (type.labelDisplay || type.label) }} | ||
</TabTitle> | ||
<a | ||
:href="href" | ||
@click="selectType" | ||
@mouseenter="setNear(true)" | ||
@mouseleave="setNear(false)" | ||
> | ||
<span | ||
v-if="type.labelKey" | ||
class="label" | ||
><t :k="type.labelKey" /></span> | ||
<span | ||
v-else | ||
v-clean-html="type.labelDisplay || type.label" | ||
class="label" | ||
:class="{'no-icon': !type.icon}" | ||
/> | ||
<span | ||
v-if="showCount" | ||
>{{ count }}</span> | ||
</span> | ||
</a> | ||
v-if="showFavorite || namespaceIcon || showCount" | ||
class="count" | ||
> | ||
<Favorite | ||
v-if="showFavorite" | ||
:resource="type.name" | ||
/> | ||
<i | ||
v-if="namespaceIcon" | ||
class="icon icon-namespace" | ||
:class="{'ns-and-icon': showCount}" | ||
data-testid="type-namespaced" | ||
/> | ||
<span | ||
v-if="showCount" | ||
data-testid="type-count" | ||
>{{ count }}</span> | ||
</span> | ||
</a> | ||
</li> | ||
</router-link> | ||
<li | ||
v-else-if="type.link" | ||
class="child nav-type" | ||
data-testid="link-type" | ||
> | ||
<a | ||
:href="type.link" | ||
:target="type.target" | ||
rel="noopener noreferrer nofollow" | ||
@click="selectType" | ||
@mouseenter="setNear(true)" | ||
@mouseleave="setNear(false)" | ||
Comment on lines
-199
to
-201
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
> | ||
<span class="label">{{ type.label }} <i class="icon icon-external-link" /></span> | ||
</a> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
near
really should be mouseover it seems.