intl 多语言国际化,自动补全locale createNavigation ,createLocalizedPathnamesNavigation(已弃用)

 
 
注意:app  router   的多语言   next.config.js 中配置i18n不起作用
import { createNavigation } from 'next-intl/navigation'

export const { Link, redirect, usePathname, useRouter, getPathname } =
createNavigation({ locales, localePrefix, pathnames });


页面的路由跳转和link  用这里导出的即可。
 
import createMiddleware from 'next-intl/middleware'
import { localePrefix, defaultLocale, locales, pathnames } from './config'
import { NextRequest, NextResponse } from 'next/server'
import authMiddleware from './lib/auth-middleware'
import { getSession, getStoreValue, setSession } from './lib/utils'

// export default createMiddleware({
//   defaultLocale,
//   locales,
//   localePrefix,
//   pathnames,
// });

export async function middleware(request: NextRequest) {
  const handleI18nRouting = createMiddleware({
    defaultLocale,
    localePrefix,
    pathnames,
    locales,
  })
  let response = handleI18nRouting(request)
  return response

  

posted @ 2024-11-06 19:05  红苹果学园  阅读(6)  评论(0编辑  收藏  举报