Last active
April 17, 2021 19:43
-
-
Save boydaihungst/a43e7adcd046c38293f0792448307bd4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script lang="ts"> | |
import { defineComponent } from 'vue'; | |
export default defineComponent({ | |
name: 'Locale', | |
}); | |
</script> | |
<template> | |
<router-view /> | |
</template> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
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