File tree Expand file tree Collapse file tree 3 files changed +33
-7
lines changed Expand file tree Collapse file tree 3 files changed +33
-7
lines changed Original file line number Diff line number Diff line change @@ -8,16 +8,14 @@ export default defineConfig({
88 locales : {
99 root : {
1010 label : "한국어" ,
11+ link : "/ko/" ,
1112 ...ko ,
12- link : "/ko" ,
1313 } ,
14+
1415 en : {
1516 label : "English" ,
17+ link : "/en/" ,
1618 ...en ,
17- link : "/en" ,
1819 } ,
1920 } ,
20- rewrites : {
21- "/ko" : "/" ,
22- } ,
2321} ) ;
Original file line number Diff line number Diff line change 1+ function nextPath ( to : "en" | "ko" , path : string ) : string {
2+ if ( path === "/" || path === "/en/" || path === "/ko/" ) {
3+ return to === "en" ? "/en/" : "/" ;
4+ }
5+
6+ return to === "en"
7+ ? path . replace ( / ^ \/ k o (? = \/ | $ ) / , "/en" )
8+ : path . replace ( / ^ \/ e n (? = \/ | $ ) / , "/ko" ) ;
9+ }
10+
11+ export function fixLangLinks ( pathname : string ) {
12+ document
13+ . querySelectorAll < HTMLAnchorElement > ( 'a.VPLink.link[href^="/en"]' )
14+ . forEach ( ( a ) => a . setAttribute ( "href" , nextPath ( "en" , pathname ) ) ) ;
15+
16+ document
17+ . querySelectorAll < HTMLAnchorElement > (
18+ 'a.VPLink.link[href^="/ko"], a.VPLink.link[href="/"]'
19+ )
20+ . forEach ( ( a ) => a . setAttribute ( "href" , nextPath ( "ko" , pathname ) ) ) ;
21+ }
Original file line number Diff line number Diff line change 11// https://vitepress.dev/guide/custom-theme
2- import { h } from "vue" ;
32import type { Theme } from "vitepress" ;
43import DefaultTheme from "vitepress/theme" ;
4+ import { h } from "vue" ;
5+ import { fixLangLinks } from "../libs/nextPath.mts" ;
56import "./style.css" ;
67
78export default {
@@ -11,5 +12,11 @@ export default {
1112 // https://vitepress.dev/guide/extending-default-theme#layout-slots
1213 } ) ;
1314 } ,
14- enhanceApp ( { app, router, siteData } ) { } ,
15+ enhanceApp ( { app, router, siteData } ) {
16+ if ( typeof window === "undefined" ) return ;
17+ fixLangLinks ( window . location . pathname ) ;
18+ router . onAfterRouteChanged = ( to ) => {
19+ fixLangLinks ( to ) ;
20+ } ;
21+ } ,
1522} satisfies Theme ;
You can’t perform that action at this time.
0 commit comments