Skip to content

Commit

Permalink
Change Schedule link to be new custom link
Browse files Browse the repository at this point in the history
This link will allow us to not care about remembering to include
localePath and will correctly add the is-active class to link,
regardless of the query or hash

This change will be added to other links later, to avoid
breaking anything major right before a push. This is the only
page that will really benefit now as is.
  • Loading branch information
BobChao87 committed Sep 23, 2021
1 parent 739703b commit 3ca4f32
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
41 changes: 41 additions & 0 deletions components/element/Link.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!--
This is a custom linker to deal with a deficit in the Vue Router linking system
Route matching only occur as route.startsWith(link) or route === link, neither of
which work correctly universally. This will apparently be addressed more generally
in the future.
See: https://github.com/vuejs/rfcs/pull/136
See also: https://github.com/vuejs/vue-router/issues/2040

This is also somewhat nice to centralize the localePath logic, so we don't have
to type it absolutely everywhere.
-->

<template>
<NuxtLink :to="path" :class="isActive">
<slot />
</NuxtLink>
</template>

<script lang="ts">
import Vue from 'vue';
import { IsActive } from '~/types/components/is-active';

export default Vue.extend({
props: {
to: {
type: String,
default: '',
},
},
computed: {
isActive(): IsActive {
return {
'is-active': this.$route.path === this.path,
};
},
path(): string {
return this.localePath(this.to);
},
},
});
</script>
4 changes: 2 additions & 2 deletions components/marathon/sidebar/Overview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
</NuxtLink>
</li>
<li>
<NuxtLink :to="localePath(`/marathon/${marathonId}/schedule`)">
<ElementLink :to="`/marathon/${marathonId}/schedule`">
<FontAwesomeIcon class="menu-item-icon" :icon="[ 'fas', 'calendar' ]" />
<span class="menu-item-label">
{{ $t('marathon.menu.schedule') }}
</span>
</NuxtLink>
</ElementLink>
</li>
<li>
<NuxtLink :to="localePath(`/marathon/${marathonId}/submissions`)">
Expand Down

0 comments on commit 3ca4f32

Please sign in to comment.