如何获取 LocalePath() 并返回 Nuxt3 服务器中语言环境的路径

问题描述 投票:0回答:1

如何从 Nuxt 3 服务器获取 localePath() ?

// server/api/[...].ts

export default NuxtAuthHandler({
    // The secret is used to encrypt the JWT token
    secret: useRuntimeConfig().auth.secret,

    // Redirects to this page if the user is not authenticated
    pages: {
        // * How to get the locales Path and return?
        signIn: '/zh-TW/auth/',  // '/en-US/auth/'
    },
....

i18n 只能在 Nuxt3 中使用,而不能在 Nitro 中使用。我可以做什么来将具有区域设置路径的路径从服务器重定向到前端?

typescript nuxtjs3 nuxt-auth nuxt-i18n
1个回答
0
投票

这不是最好的方法,但您可以使用 cookie 来了解区域设置。为此,您可以使用

parseCookies()
,如文档中所示

export default defineEventHandler((event) => {
  ...
  const cookies = parseCookies(event)
  ...
})

如果我找到更好的方法,我会更新此回复。

© www.soinside.com 2019 - 2024. All rights reserved.