Skip to content

Instantly share code, notes, and snippets.

@boydaihungst
Last active April 17, 2021 19:43
Show Gist options
  • Save boydaihungst/a43e7adcd046c38293f0792448307bd4 to your computer and use it in GitHub Desktop.
Save boydaihungst/a43e7adcd046c38293f0792448307bd4 to your computer and use it in GitHub Desktop.
<script lang="ts">
import { defineComponent } from 'vue';
export default defineComponent({
name: 'Locale',
});
</script>
<template>
<router-view />
</template>
router.beforeEach(async (to, from, next) => {
const localeInParams = getLocaleFromParams(to.params); //DIY
const isNewLocale =
localeInParams !== undefined && localeInParams !== currentLocale;
if (isNewLocale) {
const isNewLocaleSupported = SUPPORT_LOCALES.includes(localeInParams);
if (!isNewLocaleSupported) {
return next(redirectToFallbackLocale(currentLocale, to.fullPath));
}
await localeMessageChange(i18n, localeInParams);
}
next(true);
}
{
path: '/:locale?',
component: () => import(/* webpackPrefetch: true */ '@views/locale.vue'),
children: [
{
path: '',
name: 'HOME',
component: () => import(/* webpackPrefetch: true */ '@views/home.vue'),
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment