Skip to content

Commit 458c83d

Browse files
committed
Remove trailing slash before query parameters in example detail URLs
- Update handleExampleSelect function to generate URLs without trailing slash before ?id parameter - This changes URLs from /example-detail/?id=... format to /example-detail?id=... format - Ensure consistent URL format without unnecessary trailing slashes
1 parent 46f4d47 commit 458c83d

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

docs/src/pages/example-detail.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -313,16 +313,21 @@ export default function ExampleDetail() {
313313
setExampleId(selectedExample.id);
314314
setCode(selectedExample.code);
315315

316-
// 更新URL参数,保持当前语言路径前缀
316+
// 更新URL参数,保持当前语言路径前缀,但去除路径末尾的斜杠
317317
const currentPath = window.location.pathname;
318318
const currentLangPrefix = currentPath.startsWith('/zh/') ? '/zh' :
319319
currentPath.startsWith('/en/') ? '/en' : '';
320320

321-
// 构建正确的URL,处理语言前缀
321+
// 构建正确的URL,处理语言前缀,但不包含末尾斜杠
322322
let newUrlPath = currentLangPrefix ? `${currentLangPrefix}/example-detail` : '/example-detail';
323-
const newUrl = new URL(window.location.origin + newUrlPath);
324-
newUrl.searchParams.set('id', selectedExample.id);
325-
window.history.replaceState({}, '', newUrl.toString());
323+
// 确保路径不以斜杠结尾,使查询参数直接连接
324+
if (newUrlPath.endsWith('/')) {
325+
newUrlPath = newUrlPath.slice(0, -1);
326+
}
327+
328+
// 构建URL字符串,直接连接查询参数
329+
const newUrlString = `${window.location.origin}${newUrlPath}?id=${selectedExample.id}`;
330+
window.history.replaceState({}, '', newUrlString);
326331

327332
// 立即运行新代码,使用新的代码内容,避免依赖可能未更新的状态
328333
setTimeout(() => {

0 commit comments

Comments
 (0)