Skip to content

Commit

Permalink
Changing language doesn't break active links
Browse files Browse the repository at this point in the history
Changing languages would add trailing slashes so links didn't match
  • Loading branch information
BobChao87 committed Jan 21, 2022
1 parent fa4cfff commit 87a8882
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion components/element/Link.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import Vue from 'vue';
import { Location } from 'vue-router';
import { IsActive } from '~/types/components/is-active';

/** Used to normalize paths to not have trailing slashes */
const pathFixer = /\/+$/;

export default Vue.extend({
props: {
to: {
Expand All @@ -37,7 +40,7 @@ export default Vue.extend({
computed: {
isActive(): IsActive {
return {
'is-active': !this.noActive && ((this.isHash ? this.$route.hash : this.$route.path) === this.path),
'is-active': !this.noActive && ((this.isHash ? this.$route.hash : this.$route.path.replace(pathFixer, '')) === this.path),
};
},
path(): string|Location {
Expand Down

0 comments on commit 87a8882

Please sign in to comment.