提交正式官网
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import type { RouterConfig } from '@nuxt/schema'
|
||||
import type { RouteRecordRaw } from 'vue-router'
|
||||
|
||||
function shouldDuplicateRoute(path: string): boolean {
|
||||
if (path.startsWith('/admin')) return false
|
||||
if (path.startsWith('/zh')) return false
|
||||
if (path.includes('pathMatch')) return false
|
||||
return true
|
||||
}
|
||||
|
||||
function duplicateRouteForZh(route: RouteRecordRaw): RouteRecordRaw {
|
||||
const zhPath = route.path === '/' ? '/zh' : `/zh${route.path}`
|
||||
|
||||
return {
|
||||
...route,
|
||||
path: zhPath,
|
||||
name: route.name ? `${String(route.name)}-zh` : undefined,
|
||||
children: route.children?.map(duplicateRouteForZh)
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
routes: (routes) => {
|
||||
const zhRoutes = routes
|
||||
.filter((route) => shouldDuplicateRoute(route.path))
|
||||
.map(duplicateRouteForZh)
|
||||
|
||||
return [...routes, ...zhRoutes]
|
||||
}
|
||||
} satisfies RouterConfig
|
||||
Reference in New Issue
Block a user