Skip to content
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

Fix ItemLink URLs when base URL is set #176

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions packages/core/app/base/components/ItemLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ switch(props.variant) {
break;
}

const appBaseURL = useRuntimeConfig().app.baseURL.replace(/\/$/, '');

/* the primary link is either the prez internal link, or the provided to string */
const url = typeof(props.to) == 'string' ? props.to : props.to?.links ? props.to?.links[0]?.value : undefined;

Expand All @@ -70,6 +72,9 @@ const secondaryUrl = props.secondaryTo !== undefined
/** determine the url is an external link */
const isExtLink = url ? url.startsWith('http') || url.startsWith('mailto') : false;

/** add UI base URL **/
const prefixedUrl = appBaseURL && url && !url.match(/^https?:\/\//) ? appBaseURL + (url.startsWith('/') ? '' : '/') + url : url;

/** check the external link is really an external link */
const isSecondaryExtLink = secondaryUrl ? secondaryUrl.startsWith('http') || secondaryUrl.startsWith('mailto') : false;

Expand Down Expand Up @@ -97,9 +102,9 @@ const linkClass = props.class ? defaultClasses + ' ' + props.class : defaultClas
<!-- ItemLink -->
<slot name="wrapper" :url="url" :title="props.title" :secondaryUrl="secondaryUrl" :target="target">
<span>
<a v-if="url && !hidePrimaryLink"
<a v-if="url && !hidePrimaryLink"
:class="linkClass"
:href="url" :title="hideTitle ? undefined : props.title"
:href="prefixedUrl" :title="hideTitle ? undefined : props.title"
:target="isExtLink ? props.target : undefined" :rel="isExtLink ? props.rel : undefined"
@click="(e:Event)=>navigateToLink(e, url!)">
<slot />
Expand Down