Skip to content

Commit 27bf8a8

Browse files
committed
Fix URL generation in example selection to ensure correct format
- Update handleExampleSelect function to generate correct URLs during example switching - Ensure proper language prefix handling in all navigation scenarios - Maintain consistent URL format without unwanted trailing slashes
1 parent dc8762d commit 27bf8a8

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

docs/src/pages/example-detail.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,15 +335,18 @@ export default function ExampleDetail() {
335335
const currentLangPrefix = currentPath.startsWith('/zh/') ? '/zh' :
336336
currentPath.startsWith('/en/') ? '/en' : '';
337337

338-
// 构建正确的URL,处理语言前缀,但不包含末尾斜杠
338+
// 构建正确的URL路径,处理语言前缀,但不包含末尾斜杠
339339
let newUrlPath = currentLangPrefix ? `${currentLangPrefix}/example-detail` : '/example-detail';
340+
340341
// 确保路径不以斜杠结尾,使查询参数直接连接
341342
if (newUrlPath.endsWith('/')) {
342343
newUrlPath = newUrlPath.slice(0, -1);
343344
}
344345

345-
// 构建URL字符串,直接连接查询参数
346+
// 构建完整的URL,使用window.location.origin确保正确的协议和主机
346347
const newUrlString = `${window.location.origin}${newUrlPath}?id=${selectedExample.id}`;
348+
349+
// 使用 replaceState 更新URL但不触发页面重载
347350
window.history.replaceState({}, '', newUrlString);
348351

349352
// 立即运行新代码,使用新的代码内容,避免依赖可能未更新的状态

0 commit comments

Comments
 (0)