Allow to access to a language directly though instance.tld/:lang
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
15
js/src/components/Utils/HomepageRedirectComponent.vue
Normal file
15
js/src/components/Utils/HomepageRedirectComponent.vue
Normal 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>
|
||||
@@ -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",
|
||||
|
||||
@@ -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 =
|
||||
|
||||
Reference in New Issue
Block a user