Skip to content

Commit

Permalink
Bring back correct href for router-link links
Browse files Browse the repository at this point in the history
Signed-off-by: Raimund Schlüßler <[email protected]>
  • Loading branch information
raimund-schluessler committed Mar 23, 2023
1 parent 9339ace commit aaf6d3e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
12 changes: 8 additions & 4 deletions src/components/NcAppNavigationItem/NcAppNavigationItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ Just set the `pinned` prop.
}"
class="app-navigation-entry-wrapper">
<component :is="isRouterLink ? 'router-link' : 'NcVNodes'"
v-slot="{ navigate, isActive }"
v-slot="{ href: routerLinkHref, navigate, isActive }"
:custom="isRouterLink ? true : false"
:to="to"
:exact="isRouterLink ? exact : null">
Expand All @@ -226,11 +226,11 @@ Just set the `pinned` prop.
class="app-navigation-entry-link"
:aria-description="ariaDescription"
:aria-expanded="opened.toString()"
:href="href || '#'"
:href="href || routerLinkHref || '#'"
:target="isExternal(href) ? '_blank' : ''"
:title="title || nameTitleFallback"
@blur="handleBlur"
@click="(event) => onClick(event, navigate)"
@click="(event) => onClick(event, navigate, routerLinkHref)"
@focus="handleFocus"
@keydown.tab.exact="handleTab">

Expand Down Expand Up @@ -643,7 +643,11 @@ export default {
},
// forward click event
onClick(event, navigate) {
onClick(event, navigate, routerLinkHref) {
// Prevent default link behaviour if it's a router-link
if (routerLinkHref) {
event.preventDefault()
}
// Navigate is only defined if it is a router-link
navigate?.(event)
this.$emit('click', event)
Expand Down
12 changes: 8 additions & 4 deletions src/components/NcListItem/NcListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@
<template>
<!-- This wrapper can be either a router link or a `<li>` -->
<component :is="to ? 'router-link' : 'NcVNodes'"
v-slot="{ navigate, isActive }"
v-slot="{ href: routerLinkHref, navigate, isActive }"
:custom="to ? true : null"
:to="to"
:exact="to ? exact : null"
Expand All @@ -209,7 +209,7 @@
:class="{ 'list-item__wrapper--active' : isActive }">
<a :id="anchorId"
ref="list-item"
:href="href"
:href="routerLinkHref || href"
:target="href === '#' ? undefined : '_blank'"
:rel="href === '#' ? undefined : 'noopener noreferrer'"
class="list-item"
Expand All @@ -219,7 +219,7 @@
@focus="handleFocus"
@blur="handleBlur"
@keydown.tab.exact="handleTab"
@click="onClick"
@click="(event) => onClick(event, routerLinkHref)"
@keydown.esc="hideActions">

<div class="list-item-content__wrapper"
Expand Down Expand Up @@ -497,7 +497,11 @@ export default {
methods: {
// forward click event
onClick(event) {
onClick(event, routerLinkHref) {
// Prevent default link behaviour if it's a router-link
if (routerLinkHref) {
event.preventDefault()
}
this.$emit('click', event)
},
Expand Down

0 comments on commit aaf6d3e

Please sign in to comment.