From 87a8882b820330458784ac6a9adf0a84e52ad463 Mon Sep 17 00:00:00 2001 From: BobChao87 Date: Thu, 20 Jan 2022 23:40:47 -0800 Subject: [PATCH] Changing language doesn't break active links Changing languages would add trailing slashes so links didn't match --- components/element/Link.vue | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/components/element/Link.vue b/components/element/Link.vue index 0542e87a..ab71795c 100644 --- a/components/element/Link.vue +++ b/components/element/Link.vue @@ -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: { @@ -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 {