14 lines
613 B
JavaScript
14 lines
613 B
JavaScript
export default defineNuxtRouteMiddleware((to, from) => {
|
||
// skip middleware on broswer
|
||
if (import.meta.browser) return
|
||
|
||
const broswerLocale = useBrowserLocale()
|
||
const cookieLocale = useCookie('i18n_redirected')
|
||
// 如果访问的是默认页面,如 http://localhost/about ,则跳转到 http://localhost/zh/about
|
||
// 如果访问的不是默认页面,如 http://localhost/en/about,则不做处理
|
||
if (to.name.includes('___en') && !/^\/en\/.*$/.test(to.path)) {
|
||
if (broswerLocale === 'zh') {
|
||
return navigateTo(`/${broswerLocale}${to.path}`)
|
||
}
|
||
}
|
||
}); |