Skip to content

Commit 98012be

Browse files
[6.x] External URLs in the nav should render as anchor tags (#14174)
Co-authored-by: Jason Varga <jason@pixelfear.com>
1 parent 9ebc676 commit 98012be

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

resources/js/components/nav/Nav.vue

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,17 @@ function handleChildClick(event, item, child) {
134134
}
135135
}
136136
137+
const cpBaseUrl = Statamic.$config.get('cpUrl');
138+
139+
function isUrlWithinControlPanel(url) {
140+
return url && (url === cpBaseUrl || url.startsWith(cpBaseUrl + '/'));
141+
}
142+
143+
function shouldRenderAsInertiaLink(item) {
144+
if (item.attributes?.target === '_blank') return false;
145+
return isUrlWithinControlPanel(item.url);
146+
}
147+
137148
Statamic.$keys.bind(['command+\\', ['[']], (e) => {
138149
e.preventDefault();
139150
toggle();
@@ -155,7 +166,7 @@ Statamic.$events.$on('nav.toggle', toggle);
155166
<DynamicHtmlRenderer v-if="item.view" :html="item.view" />
156167
<template v-else>
157168
<component
158-
:is="item.attributes?.target === '_blank' ? 'a' : Link"
169+
:is="shouldRenderAsInertiaLink(item) ? Link : 'a'"
159170
:href="item.url"
160171
v-bind="item.attributes"
161172
:class="{ 'active': item.active }"
@@ -167,7 +178,7 @@ Statamic.$events.$on('nav.toggle', toggle);
167178
<ul v-if="item.children.length && item.active">
168179
<li v-for="(child, i) in item.children" :key="i">
169180
<component
170-
:is="child.attributes?.target === '_blank' ? 'a' : Link"
181+
:is="shouldRenderAsInertiaLink(child) ? Link : 'a'"
171182
:href="child.url"
172183
v-bind="child.attributes"
173184
v-text="__(child.display)"

0 commit comments

Comments
 (0)