Allow to access to a language directly though instance.tld/:lang

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2021-11-07 21:02:36 +01:00
parent 7c4a76cc89
commit 5de0cee025
5 changed files with 46 additions and 7 deletions

View File

@@ -0,0 +1,15 @@
<template>
<div>a</div>
</template>
<script lang="ts">
import { Component, Vue } from "vue-property-decorator";
import RouteName from "@/router/name";
@Component
export default class HomepageRedirectComponent extends Vue {
created(): void {
this.$router.replace({ name: RouteName.HOME });
}
}
</script>

View File

@@ -13,7 +13,7 @@ import { groupsRoutes } from "./groups";
import { discussionRoutes } from "./discussion";
import { userRoutes } from "./user";
import RouteName from "./name";
import { i18n } from "@/utils/i18n";
import { AVAILABLE_LANGUAGES, i18n } from "@/utils/i18n";
Vue.use(Router);
@@ -183,12 +183,23 @@ export const routes = [
announcer: { message: (): string => i18n.t("Page not found") as string },
},
},
{
path: "*",
redirect: { name: RouteName.PAGE_NOT_FOUND },
},
];
for (const locale of AVAILABLE_LANGUAGES) {
routes.push({
path: `/${locale}`,
component: (): Promise<ImportedComponent> =>
import(
/* webpackChunkName: "HomepageRedirectComponent" */ "../components/Utils/HomepageRedirectComponent.vue"
),
});
}
routes.push({
path: "*",
redirect: { name: RouteName.PAGE_NOT_FOUND },
});
const router = new Router({
scrollBehavior,
mode: "history",

View File

@@ -10,6 +10,8 @@ const DEFAULT_LOCALE = "en_US";
const localeInLocalStorage = getLocaleData();
export const AVAILABLE_LANGUAGES = Object.keys(langs);
console.debug("localeInLocalStorage", localeInLocalStorage);
let language =