Skip to content

Commit b8f0abc

Browse files
committed
Fix language prefix handling in example navigation links
- Update getExampleLink function in examples.tsx to maintain language prefix when navigating to example details - Update handleBackToHome function in example-detail.tsx to maintain language prefix when returning to examples page - Ensure all example-related navigation preserves the current language context This fixes the issue where navigation links were not preserving the language prefix, causing incorrect URL paths when switching between pages in different languages.
1 parent 661fe8b commit b8f0abc

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

docs/src/pages/example-detail.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,13 @@ export default function ExampleDetail() {
205205
};
206206

207207
const handleBackToHome = () => {
208-
window.location.href = "/examples";
208+
// 获取当前语言前缀
209+
const currentLangPrefix = window.location.pathname.startsWith('/zh/') ? '/zh' :
210+
window.location.pathname.startsWith('/en/') ? '/en' : '';
211+
212+
// 返回示例页面,保持语言前缀
213+
const homeUrl = currentLangPrefix ? `${currentLangPrefix}/examples` : '/examples';
214+
window.location.href = homeUrl;
209215
};
210216

211217
const handleExampleSelect = (selectedExampleId: string) => {

docs/src/pages/examples.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,14 @@ function ExamplesHeader() {
4545
}
4646

4747
function getExampleLink(exampleId: string): string {
48-
// 跳转到示例详情页
49-
return `/example-detail?id=${exampleId}`;
48+
// 获取当前语言前缀
49+
const currentLangPrefix = typeof window !== 'undefined'
50+
? (window.location.pathname.startsWith('/zh/') ? '/zh' :
51+
window.location.pathname.startsWith('/en/') ? '/en' : '')
52+
: '';
53+
54+
// 跳转到示例详情页,保持语言前缀
55+
return currentLangPrefix ? `${currentLangPrefix}/example-detail?id=${exampleId}` : `/example-detail?id=${exampleId}`;
5056
}
5157

5258
function ExampleCard({ example }: { example: Example }) {

0 commit comments

Comments
 (0)