Skip to content

Commit c9a73fb

Browse files
committed
Simplify handleExampleSelect to basic functionality
- Revert handleExampleSelect to simpler logic to ensure example switching works - Remove complex language prefix handling that may be causing issues - Keep only essential functionality: update state, update URL, run code
1 parent e17b047 commit c9a73fb

1 file changed

Lines changed: 3 additions & 10 deletions

File tree

docs/src/pages/example-detail.tsx

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -265,21 +265,14 @@ export default function ExampleDetail() {
265265
setExampleId(selectedExample.id);
266266
setCode(selectedExample.code);
267267

268-
// 更新URL参数,保持当前语言路径前缀
269-
const currentPath = window.location.pathname;
270-
const currentLangPrefix = currentPath.startsWith('/zh/') ? '/zh' :
271-
currentPath.startsWith('/en/') ? '/en' : '';
272-
273-
// 构建正确的URL,处理语言前缀
274-
let newUrlPath = currentLangPrefix ? `${currentLangPrefix}/example-detail` : '/example-detail';
275-
const newUrl = new URL(window.location.origin + newUrlPath);
268+
// 更新URL参数
269+
const newUrl = new URL(window.location.href);
276270
newUrl.searchParams.set('id', selectedExample.id);
277271
window.history.replaceState({}, '', newUrl.toString());
278272

279-
// 立即运行新代码,使用新的代码内容,避免依赖可能未更新的状态
273+
// 立即运行新代码
280274
setTimeout(() => {
281275
if (previewRef.current) {
282-
// 使用新示例的代码直接运行,而不依赖state
283276
runCodeWithContent(selectedExample.code);
284277
}
285278
}, 0);

0 commit comments

Comments
 (0)