Skip to content

Commit 369ce3f

Browse files
committed
fix: replaceState
1 parent 1de3be4 commit 369ce3f

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

docs/.vitepress/theme/index.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,21 @@ const checkAllImagesLoaded = () => {
5050
const handleCompatRedirect = async (router: Router) => {
5151
// 兼容旧链接/短链重定向
5252
const u = location.href.substring(location.origin.length);
53+
const replace = async (url: string) => {
54+
history.replaceState(null, '', url);
55+
await router.go(url);
56+
};
5357
if (location.pathname.startsWith('/selector/')) {
5458
if (location.pathname.at(-1) === '/') {
55-
router.go('/guide/selector');
59+
replace('/guide/selector');
5660
} else {
57-
router.go(location.pathname.replace('/selector/', '/guide/'));
61+
replace(location.pathname.replace('/selector/', '/guide/'));
5862
}
59-
} else if (location.pathname === '/subscription/') {
60-
router.go('/guide/subscription');
63+
} else if (
64+
location.pathname === '/subscription/' ||
65+
location.pathname === '/subscription'
66+
) {
67+
await replace('/guide/subscription');
6168
} else if (location.pathname === '/') {
6269
const r = new URLSearchParams(location.search).get('r');
6370
if (r === '1') {

0 commit comments

Comments
 (0)